开发者

Merging two a5 pages into a singe a4 page (without using pdfnup)

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 th开发者_开发技巧e 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!


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜