Merging pdf documents with Python

Brian briangue at gmail.com
Thu Aug 19 19:05:29 EDT 2004


Assuming you've got ghostscript installed on Unix or Windows:


import os, sys

for in_file in sys.argv[1:]:
    os.system("pdf2ps %s" % in_file)

cat_cmd = 'cat '
for in_file in sys.argv[1:]:
    cat_cmd  += in_file + ".ps "
cat_cmd += "> all.ps"

os.system("ps2pdf all.ps all.pdf")
os.system("rm -f all.ps")

for in_file in sys.argv[:1]:
    os.system("rm -f %i.ps" % in_file)



"Daryl Middleton" <dmidd at chartermi.net> wrote in message news:<mailman.1965.1092927979.5135.python-list at python.org>...
> Can python be used to merge pdf documents into a single pdf file so that I
> do not have to manually insert each one. Thanks



More information about the Python-list mailing list