在.pdf文件上绘制文本

时间:2018-04-16 13:27:59

标签: pdf imagemagick magick.net

我刚开始使用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");

但它没有做到这一点。

0 个答案:

没有答案