Merging pdf documents with Python

D

Daryl Middleton

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
 
L

Larry Bates

ReportLab has a product (not free) called PageCatcher
that provides this capability. I've used it in
several projects and it works perfectly.

HTH,
Larry Bates
Syscon, Inc.
 
B

Brian

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)
 
K

Kyler Laird

Daryl Middleton said:
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

I was using a free version of PageCatcher (ReportLab) for awhile
(after using PJscript and Ghostscript). My projects manipulate
PDF submitted by hundreds of people so any incompatibility is
likely to be a problem. ReportLab couldn't handle everything we
got last year so I started searching again.

I ended up with iText.
http://itext.sourceforge.net/
It has been very solid. There was a problem once but it was
quickly fixed.
http://groups.google.com/groups?q=i...8&[email protected]&rnum=3

I usually hate using Java but I don't mind using iText through
Jython. When I use it from Zope I use os.system like this.
command = 'java -cp /var/lib/zope/instance/default/Extensions/itext-paulo-130.jar com.lowagie.tools.concat_pdf ' + string.join(piece_names) + ' ' + result_name

I'm quite happy with iText. I like that it's Free and well-
maintained. Being usable from Jython is a real bonus.

--kyler
 
B

Brian Elmegaard

Daryl Middleton said:
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

pdflatex with pdfpages is your friend. Of course you can make a
python script that runs it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,058
Members
47,668
Latest member
SamiraShac

Latest Threads

Top