将两个 a5 页面合并为一个 a4 页面(不使用 pdfnup)

发布于 2024-09-30 02:53:13 字数 619 浏览 1 评论 0原文

我使用 Dompdf 从 html 模板生成 A5 pdf 文档,Pdfnup(Pdfjam 的一部分)将它们组合成一个漂亮的单张 A4 纸,打印时有助于节省一些纸张:)

# Generate an a5 pdf 
php dompdf.php mytemplate.html -p 'A5' -f a5doc.pdf

# combine two copies of the generated A5 into a single A4 page
pdfnup a5doc.pdf a5doc.pdf --nup '2x1' 

这很好用;尽管第二步迫使我安装大量依赖项(即 Tex-Latex、pdftex 等),并且会使我的生产服务器变得混乱。我想知道是否有任何方法可以在不实际使用 Pdfnup 的情况下合并生成的文档。例如,有没有办法用 pdftk 来做到这一点?

先感谢您!

I am using Dompdf to generate A5 pdf documents from a html template and Pdfnup (Part of Pdfjam) to combine them into a nice single A4 sheet, which helps saving some paper when printing :)

# Generate an a5 pdf 
php dompdf.php mytemplate.html -p 'A5' -f a5doc.pdf

# combine two copies of the generated A5 into a single A4 page
pdfnup a5doc.pdf a5doc.pdf --nup '2x1' 

This works just fine; though the second step forces me to install a huge amount of dependencies (i.e. Tex-Latex, pdftex, ecc.) and would clutter my production server. I am wondering if is there any way to combine the generated documents without actually using Pdfnup. For example, is there any way of doing this with pdftk?

Thank you in advance!

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

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

发布评论

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

评论(4

蓝咒 2024-10-07 02:53:13

在 Debian/Ubuntu 上,我使用简单的命令成功地将 2xA5 合并到 1xA4 进行打印:

# apt-get install ghostscript pdftk psutils 
pdftk A=A5-1.pdf B=A5-2.pdf cat A1 B1 output - \
| pdf2ps -dLanguageLevel=3 - - \
| psnup -2 -Pa5 -pa4 \
| ps2pdf -dCompatibility=1.4 - A4.pdf

On Debian/Ubuntu, I managed to merge 2xA5 to 1xA4 for printing, using simple commands, by:

# apt-get install ghostscript pdftk psutils 
pdftk A=A5-1.pdf B=A5-2.pdf cat A1 B1 output - \
| pdf2ps -dLanguageLevel=3 - - \
| psnup -2 -Pa5 -pa4 \
| ps2pdf -dCompatibility=1.4 - A4.pdf
浪荡不羁 2024-10-07 02:53:13

您可以结合使用 Ghostscript 和 pdftk 来完成此操作。

操作方法如下: https://superuser.com /questions/191373/linux-based-tool-to-chop-pdfs-into-multiple-pages/192293#192293

上面链接的示例显示了如何将页面分成两半。只需相应地修改步骤,使用不同的参数...

  • ...首先将“左”页面移动到双倍大小的画布,左半部分;
  • ...然后将“右”页面移动到双倍尺寸的画布上,右半部分;
  • ...最后,将页面与 pdftk 合并。

更新:

提示:您想要使用 pdftk 的 multistampmultibackground 操作(不: >shuffle操作!)以获得想要的最终结果。

You can do it with a combination of Ghostscript and pdftk.

Here's how: https://superuser.com/questions/191373/linux-based-tool-to-chop-pdfs-into-multiple-pages/192293#192293 .

The above linked example shows how to split pages into half. Just modify the steps accordingly, using different parameters to...

  • ...first move "left" pages to a double-sized canvas, left half;
  • ...then move "right" pages to a double-sized canvas, right half;
  • ...last, combine the pages with pdftk.

Update:

Hint: You'd want to use either of pdftk's multistamp or multibackground operations (NOT: its shuffle operation!) to get the wanted final result.

唯憾梦倾城 2024-10-07 02:53:13

基于 Kurt-Pfeifle 的回答 使用 unix like shell 的代码(我还保留了 libreoffice 的行):

FileBaseName="ExampleDoc_A5_Landscape"

# required packages: gs, pdftk, coreutils:mktemp

libreoffice --headless --nodefault --convert-to pdf "${FileBaseName}.odt"

temp_pdf_dir=$(mktemp -d)
a4_page1="${temp_pdf_dir}/1.pdf"
a4_page2="${temp_pdf_dir}/2.pdf"

pdftk "${FileBaseName}.pdf" cat 1south output - | gs -o "${a4_page1}" -sDEVICE=pdfwrite -sPAPERSIZE=a4 -dFIXEDMEDIA -dPDFFitPage -
pdftk "${a4_page1}" cat 1north output "${a4_page2}"
pdftk "${a4_page1}" background "${a4_page2}" output "${FileBaseName}-A4.pdf"
rm -rf "${temp_pdf_dir}"

请注意字体原始文档中嵌入的内容将在最终 PDF 中加倍。

此过程会生成镜像对齐,因此可以在中间剪切打印的 A4 纸,并且两张 A5 页面的底部都会有此剪切边缘。

Based on Kurt-Pfeifle's answer the code using unix like shell (I also kept the line for libreoffice):

FileBaseName="ExampleDoc_A5_Landscape"

# required packages: gs, pdftk, coreutils:mktemp

libreoffice --headless --nodefault --convert-to pdf "${FileBaseName}.odt"

temp_pdf_dir=$(mktemp -d)
a4_page1="${temp_pdf_dir}/1.pdf"
a4_page2="${temp_pdf_dir}/2.pdf"

pdftk "${FileBaseName}.pdf" cat 1south output - | gs -o "${a4_page1}" -sDEVICE=pdfwrite -sPAPERSIZE=a4 -dFIXEDMEDIA -dPDFFitPage -
pdftk "${a4_page1}" cat 1north output "${a4_page2}"
pdftk "${a4_page1}" background "${a4_page2}" output "${FileBaseName}-A4.pdf"
rm -rf "${temp_pdf_dir}"

Please note that fonts embedded in the original document will be doubled in the final PDF.

This procedure generates a mirrored alignment therefore the printed A4 paper can be cut in the middle and both A5 pages will have this cut edge at their bottom.

久光 2024-10-07 02:53:13

不要过度设计这个问题。打印 A5 时,只需将打印缩放至 141%,即可使您的页面与 A4 相匹配。然后将两页打印在一页上,就完成了。

Don't over engineer this problem. When printing A5, just scale the print to 141%, which make Your pages match A4. Then print two pages on one, and You are done.
Pring 2xA5 on A4

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