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.

  • Should the fragments be overlaid, or allowed to run consecutively down the page? If applied consecutively, is it possible the fragments will overrun to a subsequent page? – roaima Feb 23 '15 at 12:52
  • consecutively one after the other, with no margin between them. it may be possible, but i should be able to know how many items can fit on a page. - so its not a must have. – Rufinus Feb 23 '15 at 12:59

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

  • its an valid option, but the content has to be text, not an image. – Rufinus Feb 25 '15 at 10:32
  • Adding requirements after I have put some time in answering your question isn't very motivating for me. Maybe PDF Meld has the features you require. You can answer your own question if it fits your purpose. By the way: you don't mention an OS on which your solution should work... – agtoever Feb 26 '15 at 16:12

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.