4

I have multiple small fragments as PDF file, depending on user input these fragments has to be combined to one page.

pdfjam and/or pdfnup do this, and works. However, the default layout is according to the pdfpages doc.

The inserted logical pages are being centered on the sheet of paper by default.

I would need to combine individual PDFs to one page starting on top with no space/margin between them.

My current command looks like:

pdfnup 1.pdf 1a.pdf 2.pdf 2a.pdf --nup 1x4 --no-landscape --outfile test.pdf 

Other solutions besides pdfjam would be OK.

K7AAY
  • 9,725
Rufinus
  • 41

3 Answers3

3

ImageMagick is a terrible idea for PDF because of the rasterization that will happen (no offense to the other reply who was just trying to be helpful)

A much better response can be found at How to merge multiple PDF files onto one page with pdftk? and the tl;dr is:

pdfjam Page1.pdf Page2.pdf --nup 2x1 --landscape --outfile Page1+2.pdf
0

What I did was to generate blank pages and add them in order to get the first two pages top aligned in portrait mode

Let's suppose your input.pdf has two pages, each -c showpage add a blank one and these two commands save the output.pdf with your two pages top aligned:

gs -q \
 -o tempfile.pdf \
 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -r300 \
 -dCompatibilityLevel="1.5" -dPDFSETTINGS="/printer" \
 -dColorConversionStrategy=/LeaveColorUnchanged \
 -dSubsetFonts=true -dEmbedAllFonts=true \
 -dFIXEDMEDIA \
 -f input.pdf -c showpage -c showpage
pdfjam -q tempfile.pdf --nup 2x2 \
 --frame false --trim '-6mm -4mm -6mm -4mm' --clip \
 --outfile output.pdf

You may set frame to true and tweak the trim (to trim input pages those amounts from left, bottom, right and top, respectively) to get the output pages as near the page borders as possible

0

You can use ImageMagick for this. It has an overwhelming amount of options, but if you dive into it you'll see that it's easy to pick up. Check an overview of all commandline options here. For your question, I used the following options:

  • -compress jpeg: to convert the pdf fragments to jpeg before putting them in the new document. I think you can also leave this option out, which will leave the pdf's as pdf inside the new document (not tested).
  • -extent: to make the pages A4 size at 150 dpi. Check the dimensions you need for your paper size and resolution. A4 at 150 dpi results in 1240x1753 pixels.
  • -resize: to resize the images/pdf's to fit the bounds of A4 size at 150 dpi. You can leave this out if you don't want the original pdf's resized. Use the same geometry as with -extent.
  • -gravity: with tells you where on the page your image is placed. NorthWest is the top-left corner.
  • -units and -density: to set the dip (in this case I chose 150 dpi)

Note that the order of operations is relevant (executed in order). So the -gravity needs to be placed before the extend. Or, as said in the manual:

If a -gravity setting occurs before another option or setting having a geometry argument that specifies an offset, the offset is usually applied to the point within the image suggested by the -gravity argument.

So my entire command was: convert *.pdf -compress jpeg -resize 1240x1753 -gravity NorthWest -extent 1240x1753 -units PixelsPerInch -density 150x150 output.pdf

agtoever
  • 6,402