5 Step 3: cook

Once you have all the individual pages processed, it is time to put it back together again (unless you prefer each page be a file). Unfortunately, there is no tool to convert a collection of PNG files back to a single PDF.

Even more unfortunately, lpr does not print PNG files correctly even if the PNG file has the proper DPI information. This means printing the PNG files to a PDF printer does not work.

First, we need to convert each PNG file to a PS (PostScript) file. The following BASH command will get it done:

for f in ‘ls single*png‘  
do  
  pngtopnm $f | pnmtops > $(basename $f .png).ps  
done  
  

Next, we can stitch all the PS files back to a single PS file:

psjoin ‘ls single-*ps‘ > output.ps

Once we have a single PS file, it is easy to convert it to a PDf file:

ps2pdf output.ps