bash - 在另一个 .pdf 文件的每一页末尾添加一个 .pdf 文件(基本上是 .png)

标签 bash shell scripting pdftk

我有一个转换为 code.pdf 的 code.ps 文件,我想将其添加到我的 test.pdf 中每一页的末尾,即缩小 test.pdf 的每一页并在其末尾添加一个图像.

我已经为它编写了以下 shell 脚本,但它在 test.pdf 的每一页之后附加了 code.pdf 作为新页面! ...请帮助。这是我的代码:-

#!/bin/sh
filename=test.pdf
pages="`pdftk $filename dump_data | grep NumberOfPages | cut -d : -f2`"
numpages=`for ((a=1; a <= $pages; a++)); do echo -n "A$a B1 "; done`
pdftk A=$filename B=code.pdf cat $numpages output $filename-alternated.pdf
exit 0

最佳答案

将图像 (image.[pdf,png] 标记到多页 pdf (text.pdf) 上的简单示例,允许使用 pdfjampdftk 手动调整缩放和偏移 可以是:

# scale and offset the text part
pdfjam --scale 0.8 --frame True --offset '0cm 2.5cm' text.pdf
# scale and offset the image
pdfjam --paper 'a4paper' --scale 0.3 --offset '7cm -12cm' image.pdf
# combine both
pdftk text-pdfjam.pdf stamp image-pdfjam.pdf output combined.pdf

这可能看起来像 enter image description here

如果您从图像文件(png、jpg)开始,您可以使用 imagemagick 将其转换为 pdf

convert image.png image.pdf

当然,比例因子和偏移量必须根据您的需要进行调整。我包含了 --frame 选项来突出显示 text.pdf 部分的缩放比例。 stamp 选项覆盖图像,而 background 选项将覆盖图像。

关于bash - 在另一个 .pdf 文件的每一页末尾添加一个 .pdf 文件(基本上是 .png),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20235541/

相关文章:

linux - 如何在 bash 中通过脚本将第二行打印到输出中

linux - 在 bash 脚本中使用 for 循环在多行命令中插入行

Bash 别名和点文件

linux - 为什么脚本无法识别文件扩展名?

linux - sh 返回 : can only `return' from a function or sourced script

linux - 如何在 bash 中使用 && 和 grep

Java:嵌入到 Java 桌面应用程序中的脚本语言(宏)

linux - 多次启动程序

bash - 匹配模式后分割多行

bash - 脚本 shell 如何将 x 分钟添加到给定日期?