How to merge pdf:s using Imagemagick (resolution problem)
Solution 1
Barns's right, but if pdftk didn't work try ghostscript.
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=temp.pdf pdf1.pdf pdf2.pdf
Solution 2
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.
Solution 3
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
Solution 4
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.
Solution 5
If running linux you can also try poppler which provides pdfunite
which concatenates without manipulating the resolution.
Related videos on Youtube
Admin
Updated on September 17, 2022Comments
-
Admin over 1 year
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?
-
Leopd over 14 yearsI'm running on OS X 10.6.1 and I tried to install pdftk via Macports. It seems that pdftk is deprecated on Mac, the installation would not finish. So, I tried to do this using Imagemagick.
-
Marco almost 12 years-1 for suggesting to rasterize a (possible) vector image. That's not the way to go.
-
Iguananaut about 11 yearsOn Ubuntu pdftk was no problem to install from apt, and it did the trick gloriously. I've used ImageMagick to stitch together PDFs before with great success, but because it rasterizes PDFs first (understandably--it doesn't work with vectors) it doesn't look so good for most text documents. But pdftk worked great--thanks for the suggestion.
-
Josh almost 10 yearsA side note on your all PDF syntax, you can omit the sub-ls command:
convert -density 150 *.pdf output.pdf
-
Brionius over 9 yearsWorked perfectly, and speedily too - much faster than using ImageMagick with the -density flag.
-
Sablefoste about 9 yearsSorry, the link is dead now.
-
Jagtesh Chadha almost 9 yearsThis should be the correct answer. Not that ImageMagick doesn't work; it works too. But as @Brionius noted, gs is much faster and the quality of the resulting pdf is top notch.
-
shantanoo over 6 years'*.pdf' and '$(ls -rt *pdf)' may result in different output.
-
Colin D over 6 yearsNote that you could use *.pdf instead of the list of pdf1.pdf and pdf2.pdf at the end of this command to convert all pdf in a folder to a single pdf.
-
lesolorzanov about 5 yearsI had some problems with the font, some pages lose their font. Is there a way I can choose it?
-
Rosamunda about 5 yearsIt's an excellent tool, and here's how to do it: unixblogger.com/how-to-easily-merge-pdf-documents-under-linux
-
Dan Ortega almost 5 yearsGreat ... thank you
-
Dan Ortega almost 5 yearsLet's upvote this one, pdftk works way better than ghostcript doing this.
-
Nathan Chappell over 3 yearshad to do a snap install, and the quality was very good.
-
Paddy Landau about 3 yearsPlease don't ever use
ls
like that. (1) If some file names have spaces or special characters, the command might fail or, worse, cause data corruption. (2)ls
doesn't have a POSIX standard, and is therefore not guaranteed to be portable. (2) You need to quote the results, but you can't do so because of the subprocess. Instead, to find files, use thefind
command or, better, use the shell as @Josh explained.