#!/usr/bin/python # Creates a single PDF file from multiple images. # Required ubuntu packages: # pdfjam # sam2p # - Thanks to http://typethinker.blogspot.com/2009/06/creating-multi-page-pdf-from-images.html import sys import subprocess import tempfile import os images = [] pdfs = [] print(len(sys.argv)) outputFile = sys.argv.pop() print(len(sys.argv)) for next in range(1, len(sys.argv)): image = sys.argv[next] print(image) images.append(image) for image in images: pdf = tempfile.mkstemp(suffix=".pdf")[1] pdfs.append(pdf) print(pdf) print(image + "->" + pdf) #subprocess.call(["/usr/bin/sam2p", image, pdf.name]) subprocess.call(["/usr/bin/sam2p", "-pdf:b2", image, pdf]) print("JOINING PDFS: ") print(pdfs) print(" as " + outputFile) p = ["/usr/bin/pdfjoin", "--outfile", outputFile] p += pdfs print(pdfs) print(p) subprocess.call(p) print("Cleaning Up") for pdf in pdfs: os.remove(pdf)
Friday, July 9, 2010
Convert set of images to a multi-page PDF
Subscribe to:
Posts (Atom)