Merging png images into one pdf file [closed]
Solution 1:
From looking through the documentation on ImageMagick, it might be as easy as:
convert 1.png 2.png myfile.pdf
See comments about possible risks. If that doesn't work, PDFjam claims to be able to solve your problem.
Solution 2:
If I want to merge some scans to one PDF file, I do this:
pdfjoin --a4paper --fitpaper false --rotateoversize false scan01.png scan02.png
This gives you a PDF document with DIN-A4 page size, where every png
file is centered on it's own page. Images that are too big for one DIN-A4 page are resized proportionally to fit on one page. Smaller images are not resized (not made bigger).
You have to name all png
files on the command line, but you can also use wildcards to eg merge all png files in the current directory:
pdfjoin --a4paper --fitpaper false --rotateoversize false *.png
The pdfjoin
command is part of PDFjam as mentioned in the answer by Jeremiah Willcock. So you will most likely have to install a package named pdfjam
or texlive-extra-utils
with your distros package manager. PDFjam is able to use png
files as input since Version 2.07, released in 2010-11-13.
Solution 3:
ImageMagick’s convert tool is my preference.
The convert program is a member of the ImageMagick suite of tools. Use it to convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.
convert [input-option] input-file [output-option] output-file`
If you want the image files (and thus, their quality and file size) unaltered, and just put a PDF container around them:
convert In.png In-2.png Someother-*.png Result.pdf
In case you want to have a smaller file size, and you are okay with a loss in quality, you can convert them to the JPEG format first. (ImageMagick also supports changing the PNG compression level, but usually your input files are already using the highest level.)
convert 1.png 2.png -compress jpeg -quality 50 Result.pdf
Use a value between 0 and 100 for the quality
option.
Alternatively, you can reach a lower file size (and quality) by resampling the images to a certain resolution.
convert *.png 2.png -resample 300 Result.pdf
The value for resample
refers to the number of pixels per inches. ImageMagick reads the original density from EXIF part of the input images, falling back to 72 dpi. You can use the density
parameter to set a custom resolution for the input images.
You can of course also combine the compress
, quality
, and resample
parameters.