本文介绍了如何使用Ghostscript将文本(传真)标题叠加到PDF和/或TIFF上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个可以传真最终用户提供的文档(许多受支持的类型)的应用程序。一个要求是最终用户还可以提供用作自定义传真标题的一部分的文本。

I'm writing an application that faxes a document (many supported types) provided by the end user. A requirement is that the end user can also provide text to be used as part of a custom fax header.

我一直在使用Ghostscript将PDF呈现为TIFF,到目前为止,它的工作一直很好,但是我还没有找到一种直接的方法来将自定义标头覆盖在PDF顶部。我已经尝试了一些建议:

I've been using Ghostscript to render PDFs as TIFFs and it's been working great so far, but I have yet to find a straightforward way of overlaying the custom header at the top of a PDF. I've tried out a few recommendations:






  • How can I make a program overlay text on a postscript file?
  • How can I add a footer to the bottom of each page of a postscript or pdf file in linux?
  • Add comments to PDF files automagically with regular expressions
  • Stamp PDF file with control for position of stamp file

...没有运气。

我我们使用ImageMagick成功地对文档rendere进行了此操作d可以通过其他工具转换为TIFF,我知道ImageMagick可以自行将PDF转换为TIFF。但是,我想坚持使用Ghostscript,因为根据我的经验,它的性能更好,并且提供了更清晰的TIFF。

I've used ImageMagick to do this successfully with documents rendered to TIFF via other tools, and I'm aware that ImageMagick can render PDF-to-TIFF on its own. However, I want to stick with Ghostscript because in my experience it has performed better and rendered clearer TIFFs.

是否可以使用Ghostscript和PS帮助程序脚本?

Is this possible using Ghostscript and perhaps a PS helper script?

编辑:

Ghostscript(v9.04)没有引发任何错误。例如:

Ghostscript (v9.04) is not throwing any errors. For example:

gswin64c -dSAFER -dBATCH -dNOPAUSE -dPDFFitPage -sDEVICE=tiffg3 ^
    -sOutputFile=goofy.tif ^
    -c "/Courier findfont 12 scalefont setfont 50 765 moveto (header text) show" ^
    -f goofy.pdf

...产生原始PDF的TIFF,但是没有我尝试添加的文本。如果我将 showpage 附加到后记单行,它将(可能是我想的)打印出一个新的空白页眉页,这对我没有多大帮助

... produces a TIFF of the original PDF, but without the text I tried to add. If I append showpage to the postscript one-liner it (predictably, I suppose) prints a new, blank-except-for-header page, which doesn't help me much.

推荐答案

我将使用另一个与Ghostscript结合使用的命令行工具来完成此任务。该工具为 pdftk.exe 。然后使用3个步骤:

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


  1. Ghostscript的任务是创建一个带有标题文本的(否则为空)页面:
  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"


  • pdftk的任务是覆盖( stamp background ),其PDF文件的文本标题位于原始PDF之上:

  • 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

    
     pdftk.exe goofy.pdf stamp header.pdf output goofy-with-header.pdf


  • 最后一步是再次使用Ghostscript来创建最终的TIFF输出:

  • 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


  • 这篇关于如何使用Ghostscript将文本(传真)标题叠加到PDF和/或TIFF上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-09 06:37