Combining two a5 pages into one a4 page (without using pdfnup)

I use Dompdf to create A5 documents from the html and Pdfnup templates (part of Pdfjam) to combine them into a good A4 sheet, which helps save 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 fine; although the second step forces me to install a huge number of dependencies (i.e. Tex-Latex, pdftex, ecc.) and clutters my production server. I am wondering if there is a way to combine the generated documents without actually using Pdfnup. For example, is there a way to do this with pdftk?

Thank you in advance!

+6
pdf-generation ghostscript pdftk dompdf
source share
3 answers

You can do this 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 example shows how to split the pages in half. Just change the steps using various options to ...

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

Update:

Hint: you want to use any pdftk multistamp or multibackground ( NOT: its shuffle operation!) To get the desired end result.

+3
source share

In Debian / Ubuntu, I was able to combine 2xA5 into 1xA4 for printing with simple commands:

 # 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 
+4
source share

Based on Kurt-Pfeifl's answer to the code using a unix-like shell (I also saved 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}" 

Note that fonts embedded in the source document will be doubled in the final PDF.

This procedure creates a mirror alignment, so A4 printed paper can be cut in the middle, and both A5 pages will have this cut edge at the bottom.

0
source share

All Articles