带有印记文件位置控制的印记 PDF 文件

发布于 2024-12-20 15:08:11 字数 266 浏览 4 评论 0原文

有谁知道如何将 PDF 文件标记为 PDF 文件以及定位 PDF 文件标记的控件吗?

我有一个文件 orinal.pdflogo.pdf。我想将 logo.pdf 文件标记为文件 original.pdf 左上角的文件 original.pdf。如何使用Ghostscriptpdftk来完成它?

Does anyone know about stamping PDF file to PDF file and also controls for positioning PDF file stamp?

I have a file orginal.pdf and logo.pdf. I want to stamp logo.pdf file to file orginal.pdf at the top left of file original.pdf. How can it be done with Ghostscript or pdftk?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴梦长久 2024-12-27 15:08:11

可以使用 Ghostscript plus pdftk 来完成,但它至少需要 2 个不同的步骤。

AFAIK,您无法直接控制 pdftk 的图章位置。默认情况下,它将图章放在页面的中心,同时执行“缩放以适合”操作。

因此,您必须先修复印章,以便首先将其放置在空白页面上,就在您想要的位置。您可以在 Ghostscript 的帮助下第一步实现这一点。然后,在第二步中,使用 pdftk 合并两个文件。

让我们举个例子。

首先:创建“stamp-small.pdf”。 (你已经有你的了;我需要一个来演示原理。)

gs \
  -o stamp-small.pdf \
  -sDEVICE=pdfwrite \
  -g3200x500 \
  -c "/Helvetica-Bold findfont 36 scalefont setfont" \
  -c "0 .8 0 0 setcmykcolor" \
  -c "12 12 moveto" \
  -c "(This is my stamp) show" \
  -c "showpage"

这个例子适用于 Linux 或 Mac OS X。在 Windows 上,你可以像这样修改它:(

gswin32c.exe ^
  -o stamp-small.pdf ^
  -sDEVICE=pdfwrite ^
  -g3200x500 ^
  -c "/Helvetica-Bold findfont 36 scalefont setfont" ^
  -c "0 .8 0 0 setcmykcolor" ^
  -c "12 12 moveto" ^
  -c "(This is my stamp) show" ^
  -c "showpage"

你也可以将其全部放在一行中,但然后跳过该行- 相应操作系统的连续标记。)第一个命令将一系列简单的 PostScript 语句传递给 Ghostscript 的命令行,并告诉它创建一个尺寸为 320x50 pts 的小 PDF 页面。这应该模拟您寻求放置的“小”邮票。

第二:创建一个全页(在我的例子中是 A4 大小)PDF 文件,可以在第三步中将其应用为真正的图章:

gs \
  -o A4-stamp.pdf \
  -sDEVICE=pdfwrite \
  -g5950x8420 \
  -c "<</PageOffset [280 790]>> setpagedevice" \
  -f stamp-small.pdf 

在 Windows 上:

gswin32c.exe ^
  -o A4-stamp.pdf ^
  -sDEVICE=pdfwrite ^
  -g5950x8420 ^
  -c "<</PageOffset [280 790]>> setpagedevice" ^
  -f stamp-small.pdf 

了几件事:

  1. 此命令实现 最初创建的“stamp-small.pdf”作为输入。
  2. 它使用 595x842 pts 的画布(即 ISO A4 页面大小)。
  3. 它应用一个小的 PostScript 命令将输入​​内容向右移动 280 点,向顶部移动 790 点(PostScript 和 PDF 坐标从左下角开始计数)。
  4. 它创建“A4-stamp.pdf”作为输出。

实际上,我原来的小尺寸邮票串现在位于 A4 页面的右上角。

第三:现在您可以使用 pdftk 将这个新的“标记”应用到您的原始 PDF 文件:

pdftk original.pdf stamp A4-stamp.pdf output stamped.pdf

或者,标记多页原始 PDF 的所有页面:

pdftk original.pdf multistamp A4-stamp.pdf output stamped.pdf

这个示例应该让您对以下内容有足够的了解:如何为您自己的 logo.pdf 开发类似的程序,就像我为我的 stamp-small.pdf 所做的那样。 (我是在右上角做的,你想在左上角做你的。)

It can be done with Ghostscript plus pdftk, but it requires at least 2 different steps.

AFAIK, you cannot directly control pdftk's stamp placement. By default it puts the stamp on the center of the page, and at the same time does a 'scale-to-fit' operation.

So, you have to fix your stamp first so it is placed on an empty page first, right at the position you want it. This you can achieve with the help of Ghostscript in a first step. Then, in a second step, use pdftk to merge the two files.

Let's use an example.

First: Create a 'stamp-small.pdf'. (You have yours already; I need one to demonstrate the principle.)

gs \
  -o stamp-small.pdf \
  -sDEVICE=pdfwrite \
  -g3200x500 \
  -c "/Helvetica-Bold findfont 36 scalefont setfont" \
  -c "0 .8 0 0 setcmykcolor" \
  -c "12 12 moveto" \
  -c "(This is my stamp) show" \
  -c "showpage"

This example was for Linux or Mac OS X. On Windows you would modify it like this:

gswin32c.exe ^
  -o stamp-small.pdf ^
  -sDEVICE=pdfwrite ^
  -g3200x500 ^
  -c "/Helvetica-Bold findfont 36 scalefont setfont" ^
  -c "0 .8 0 0 setcmykcolor" ^
  -c "12 12 moveto" ^
  -c "(This is my stamp) show" ^
  -c "showpage"

(You could also put it all in one line, but then skip the line-continuation marks for the respective OS.) This first command hands a series of simple PostScript statements to Ghostscript's commandline and tells it to create a small PDF page with a dimension of 320x50 pts. This should simulate your 'small' stamp which you seek placement for.

Second: Create a full-page (in my case, an A4-sized) PDF file which can be applied in the third step as the real stamp:

gs \
  -o A4-stamp.pdf \
  -sDEVICE=pdfwrite \
  -g5950x8420 \
  -c "<</PageOffset [280 790]>> setpagedevice" \
  -f stamp-small.pdf 

On Windows:

gswin32c.exe ^
  -o A4-stamp.pdf ^
  -sDEVICE=pdfwrite ^
  -g5950x8420 ^
  -c "<</PageOffset [280 790]>> setpagedevice" ^
  -f stamp-small.pdf 

This command achieved several things:

  1. It took the initially created 'stamp-small.pdf' as input.
  2. It used a canvas of 595x842 pts (that is ISO A4 page size).
  3. It applies a small PostScript command to shift the input content by 280 pts to the right and 790 pts to the top (PostScript and PDF coordinates start counting from the lower left corner).
  4. It creates 'A4-stamp.pdf' as output.

Effectively, my original small-sized stamp string is now in the top right corner of an A4 page.

Third: Now you can apply this new 'stamp' to your original PDF file using pdftk:

pdftk original.pdf stamp A4-stamp.pdf output stamped.pdf

or, to stamp all pages of a multi-page original PDF:

pdftk original.pdf multistamp A4-stamp.pdf output stamped.pdf

This example should give you enough of an idea about how to develop a similar procedure for your own logo.pdf as I did for my stamp-small.pdf. (I did it for the top right corner, you want yours for the top left corner.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文