68

When I try to merge two .pdf files using Imagemagick

convert pdf1.pdf pdf2.pdf temp.pdf

the resulting temp.pdf file seems to have very low resolution. How can I keep the resolution same as in the source files?

6 Answers6

74

Barns's right, but if pdftk didn't work try ghostscript.

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=temp.pdf pdf1.pdf pdf2.pdf
32

If every file you want to merge is in the same folder:

convert -density 150 $(ls -rt *pdf) output.pdf

the argument -density 150 keeps the quality of the merged PDFs.

slhck
  • 235,242
juda
  • 329
27

Imagemagick's convert command is normally used for converting image files from one format to another, and in this case, it is possible that it is actually performing an internal conversion of sorts before outputting the two "images" (PDFs) into a single file.

I would suggest you consider using the PDF Toolkit (pdftk) instead http://www.accesspdf.com/pdftk/

From the examples on the website, this should be as simple as:

pdftk pdf1.pdf pdf2.pdf cat output temp.pdf
Richard
  • 371
12

I always forget how to do this and find this question first when I search.

convert -density 600 file1.pdf file2.pdf -resize 50% new.pdf

The linked example has the density at 144, however, that has never been high enough to not appear pixelated.

http://web.archive.org/web/20130311071316/http://studio.imagemagick.org/pipermail/magick-users/2009-September/022958.html

9

If running linux you can also try poppler which provides pdfunite which concatenates without manipulating the resolution.

haytona
  • 91
  • 1
  • 1
1

I couldn't find any way of joining two pdf files together while keeping the resolution good and the text intact, but I figured out a way to convert it into a high resolution png file.

pdftoppm -f 1 -l 1 -aa yes -aaVector yes -png -r 300 page.pdf > tmp1.png
pdftoppm -f 2 -l 2 -aa yes -aaVector yes -png -r 300 page.pdf > tmp2.png
convert tmp1.png tmp2.png +append -quality 100 page.png

This takes to first two pages of page.pdf and joins them into a side by side high resolution png file.

Changing the last line to

convert tmp1.png tmp2.png +append -quality 100 page.pdf

will result in a pdf document output as I later figured out after messing around with pngtopnm, pnmtops, ps2pdf.