can I use Ghostscript to overlay a text (fax) header onto a PDF and/or TIFF?

梦想的初衷 提交于 2019-11-30 16:03:51

I would use another commandline tool combined with Ghostscript for this task. This tool is pdftk.exe. Then use a 3 step approach:

  1. The task of Ghostscript would be to create an (otherwise empty) page with the header text:
    gswin64c.exe ^
      -o header.pdf ^
      -sDEVICE=pdfwrite ^
      -c "/Courier findfont 12 scalefont setfont" ^
      -c "50 765 moveto (header text) show showpage"
    
  2. The task of pdftk would be to overlay (stamp or background) the PDF file with the text header over the original PDF:
     pdftk.exe goofy.pdf background header.pdf output goofy-with-header.pdf
    or
     pdftk.exe goofy.pdf stamp header.pdf output goofy-with-header.pdf
  3. The last step is to employ Ghostscript again in order to create your final TIFF output:
    gswin64c.exe ^
       -dPDFFitPage ^
       -o goofy-with-header.tif ^
       -sDEVICE=tiffg3 ^
        goofy-with-header.pdf

The way I see doping it is appending what you need on the PDF to the PDF file itself - before any conversion - the PDF filew format is designed so that one can append extra information at the end of the file (even information that goes on previous pages).

Unfortunatelly, I never worked on it - so I can'tell you eactly what you need to do - maybe there is aome PDF editing library in a programing language that would make this task easier - else you will have to create the PDF bits yourself. (Tradiditional libraries that render PDF's from some input format won't do, as you have to work inside the structure of your existing document) - but maybe taking a looka t the PDF specification can enlighten you on this approacj, and you check if it is worth: http://www.adobe.com/devnet/pdf/pdf_reference_archive.html

Another approach there would be to work on the "other end" of your files: layout text on the post-rendered TIFF files using an image manipulation library. This is only possible, of course, if there is a fixed space on the pages reserved for you to add the information.

Sorry for not being able to offer a complete solution

I just tried your exact same approach with your exact same result. Then I removed -dSAFER from my command-line arguments and it works like a charm.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!