1

我刚开始使用 Magick.net,但这不是我第一次看到 ImageMagick 的感觉,前段时间我玩过它并设法做到了这一点:

@echo off
setlocal


::--------------------------------------------------------
   ::PDF File location
Set "PDFDir=C:\PDF"
   ::ImageMagick version
   ::32 or 64
Set "IMv=32"

::--------------------------------------------------------
   :: Batch file location
Set "eXeDir=%~dp0"
::--------------------------------------------------------
   ::First Text
Set "Text1=C.O.O.L."
   :: First Text Font
Set "Font1=Arial"
::--------------------------------------------------------
   ::Second Text
Set "Text2=This is a super cool text on a super cool pdf file writen by:"
   :: Second Text Font
Set "Font2=Arial-Narrow"
::--------------------------------------------------------
   ::3rd Text
Set "Text3=ME!"
   :: 3rd Text Font
Set "Font3=Arial"
::--------------------------------------------------------


echo Just wait while I write in here.
  for %%F in ("%PDFDir%\*.pdf") do (
   rem echo "%%~nxF"
   "%eXeDir%\gs\bin\gswin32c.exe" -q -dNOPAUSE -r200 -sDEVICE=tiffgray -sOutputFile="%eXeDir%\temp\temp.tif" "%%F" -c quit
::  -strip -quality 90 to lower quality 
   "%eXeDir%\ImageMagick%IMv%\convert.exe" "%eXeDir%\temp\temp.tif" -font %Font1% -pointsize 200 -strokewidth 3 -draw "gravity north fill none stroke gray text 0,9  '%Text1%'" -font %Font2% -pointsize 80 -strokewidth 2 -draw "gravity center fill none stroke gray rotate -45 text 0,9 '%Text2%'" -font %Font3% -pointsize 200 -strokewidth 3 -draw "gravity south fill none stroke gray text 0,9  '%Text3%'" -compress jpeg  "%PDFDir%\%%~nxF" 
)

Pause. >nul | echo. All Done here.

将 pdf 文件转换为多页 Tiff,然后在 tiff 上绘制,然后将其转换回 pdf.... 我希望有更好的方法来做到这一点,因为我想更改 A3 页面的字体大小和风景/肖像,并希望尽可能保持清洁。
在玩 ghithub 文档时,我试过这个:

    using (MagickImage image = new MagickImage(@"H:\\Test\Project C\bin\Debug\cool2.pdf"))
    {
        new Drawables()
          // Draw text on the image
          .Font("Arial")
          .FontPointSize(200)
          .StrokeWidth(3)
          .StrokeColor(new MagickColor("gray"))
          .FillColor(MagickColors.None)
          .Gravity(Gravity.North)
          .TextAlignment(TextAlignment.Center)
          .Text(300, 100, "C.O.O.L")
          .Draw(image);

        image.Format = MagickFormat.Pdfa ;
        image.Write("sdas" + ".pdf");

但它不成功。

4

0 回答 0