[reportlab-users] Combining reportlab's PDF and pypdf to partially create, partially copy?
Ken Corey
ken at kencorey.com
Fri Apr 17 10:01:30 EDT 2009
Hi All,
I'm aiming to generate (on Google AppEngine in Python) a single PDF
document made up of some sections created programatically, while others
are existing PDF files on disk.
So, I tried a little function:
-------------------------------------------
class GetPDFPage(AllPages):
def get(self):
self.response.headers['Content-Type'] = 'application/pdf'
p = Canvas(self.response.out)
p.drawString(100, 750, "Hey, it's easy!.")
p.showPage()
p.save()
-------------------------------------------
It worked a treat!
So then I tried this:
-------------------------------------------
class GetPDFPage(AllPages):
def get(self):
self.response.headers['Content-Type'] = 'application/pdf'
outputPDF = PdfFileWriter()
p = Canvas(self.response.out)
p.drawString(100, 750, "Hey, it's easy!.")
p.showPage()
p.save()
pdfList = glob.glob( '*.pdf')
for chapPdf in pdfList:
pdfInput = PdfFileReader(file(chapPdf, "rb"))
for i in xrange(pdfInput.getNumPages()):
outputPDF.addPage(pdfInput.getPage(i))
outputPDF.write(self.response.out)
-------------------------------------------
But the funny thing is that the output was *only* the files loaded from
the disk, and the stuff generated by Canvas wasn't there at all.
Anyone know why? Anyone know how to get around it so that I can crate a
page using reportlabs, and then a few pages from existing PDF files, and
then generate some more pages, and so on?
Thanks!
-Ken
More information about the reportlab-users
mailing list