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

4

9

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!

Unpack answered 3/11, 2010 at 12:30 Comment(3)
-nup option of pdfnup should be read as --nup.Grisgris
Did you realized this job? If yes, did you use the hint of Kurt Pfeifle? I am not really sure how to change the given parameters to fit your problem. If you was successfull, could you maybe share (a part of) your solution?Spiny
Same question on SuperUser: linux - How to convert a 1 page PDF to a 2 page per sheet PDF? - Super UserHayse
C
3

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.

Chenoweth answered 5/12, 2010 at 11:17 Comment(3)
The outputs of your first and second steps are different files, correct? Which pdftk command will combine corresponding pages from separate files to the same page of the output, per step 3?Mississippian
@JeffG: Please comment under the original question. Over there, the instructions are very clear IMHO, if taken together with the illustrations I made. OTOH, your current questions are not clear to me at all. Please try to ask them again, but in a clear way.Chenoweth
My question is not about how to chop a single page into multiple pages (the other question, which yes is very clear!). Instead, I'm asking for clarification about your answer here -- i.e. how to adapt your other answer to combine multiple pages into a single page. In my question here about the "steps", I'm referring to your 3 bullets just above: (1) move left pages to double-sized canvas (2) move right pages similarly, and (3) combine pages with pdftk. In short: would you use pdftk shuffle even for the merging the left- and right- halves? How?Mississippian
D
10

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
Donaugh answered 8/12, 2014 at 15:0 Comment(3)
Thanks, since Ubuntu 18.? removed pdftk i had to install it manual refer to this fine install script askubuntu.com/a/1046476/617935Tuft
It could be helpful to add east/west to rotate the input pdfs, because a5 fits perfectly twice in a4. Here is a solution one could put in .bashrc e.g.: function pdfa5toa4() {pdftk A=$1 B=$2 cat A1east B1east output - | pdf2ps -dLanguageLevel=3 - - | psnup -2 -Pa5 -pa4 | ps2pdf -dCompatibility=1.4 - $3} and use with pdfa5toa4 A5-1.pdf A5-2.pdf output.pdfJoleen
Some people need to add ps2pdf (as pdf2pdf) to @colidyre’s answer to fix issues with the PDFs, so <Midwinter-A5.pdf pdf2ps -dLanguageLevel=3 - - | psnup -q -2 -Pa5 -pa4 | ps2pdf14 - Midwinter-A4.pdf would do, but a PDF using TrueType fonts suffers from massive quality loss (glyphs jump around). I found pdfjam --nup 2x1 --landscape --a4paper Midwinter-A5.pdf --outfile Midwinter-A4.pdf to help… though it of course needs Tₑχ/LᴬTᴇΧ which the OP wants to avoid. Still posting here in case someone else stumbles upon it who, like me, has texlive-full installed anyway.Adviser
C
3

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.

Chenoweth answered 5/12, 2010 at 11:17 Comment(3)
The outputs of your first and second steps are different files, correct? Which pdftk command will combine corresponding pages from separate files to the same page of the output, per step 3?Mississippian
@JeffG: Please comment under the original question. Over there, the instructions are very clear IMHO, if taken together with the illustrations I made. OTOH, your current questions are not clear to me at all. Please try to ask them again, but in a clear way.Chenoweth
My question is not about how to chop a single page into multiple pages (the other question, which yes is very clear!). Instead, I'm asking for clarification about your answer here -- i.e. how to adapt your other answer to combine multiple pages into a single page. In my question here about the "steps", I'm referring to your 3 bullets just above: (1) move left pages to double-sized canvas (2) move right pages similarly, and (3) combine pages with pdftk. In short: would you use pdftk shuffle even for the merging the left- and right- halves? How?Mississippian
D
0

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.

Dressingdown answered 27/1, 2019 at 22:10 Comment(0)
G
0

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

Gannon answered 1/7, 2023 at 16:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.