convert multiple images to a PDF
Let's assume you have scanned 10 pages from a book to files
page1.png, page2.png, ..., page10.png. We'll use
ImageMagick's
convert for the conversion.
- to reduce the final filesize, you can first reduce the color map size of the files, for example:
convert page1.png -colors 32 page1b.png
(increase/decrease the number 32 depending on how many different colors you'd like to see in the final PDF) - if you're running tcsh as your shell, you can do all pages in one go by:
foreach f (1 2 3 4 5 6 7 8 9 10)
convert page$f.png -colors 32 page${f}b.png
end - if you're running bash, you could do:
for f in $(seq 10)
do
convert page$f.png -colors 32 page${f}b.png
done - convert the resulting images into a single PDF:
convert page*b.png mydoc.pdf
If you get an incorrect page count (recently I saw this when converting two PNG files to a PDF, it gave me page count of 1), you can try the following:
- convert page*.png mydoc.ps
- ps2pdf13 mydoc.ps
- if stuff from a scanned A4 page does not show up correctly, you can try:
ps2pdf13 -sPAPERSIZE=a4 mydoc.ps
(so you first convert to PostScript. ps2pdf13 is part of the ghostscript package)
A helpful note from Quique: you can also use convert's option -quality 100 to improve the resulting PDF.
Send me your comments!
Something didn't work as expected? You'd like to add some useful info to this tip? Use the form below to send me your comments. (Don't forget to fill out the super-lame CAPTCHA below..)