Jiri
Jiri

Reputation: 16625

How to include page in PDF in PDF document in Python

I am using reportlab toolkit in Python to generate some reports in PDF format. I want to use some predefined parts of documents already published in PDF format to be included in generated PDF file. Is it possible (and how) to accomplish this in reportlab or in python library?

I know I can use some other tools like PDF Toolkit (pdftk) but I am looking for Python-based solution.

Upvotes: 5

Views: 3786

Answers (3)

nakedfanatic
nakedfanatic

Reputation: 3158

If you want to place existing PDF pages in your Reportlab documents I recommend pdfrw. Unlike PageCatcher it is free.

I've used it for several projects where I need to add barcodes etc to existing documents and it works very well. There are a couple of examples on the project page of how to use it with Reportlab.

A couple of things to note though:

If the source PDF contains errors (due to the originating program following the PDF spec imperfectly for example), pdfrw may fail even though something like Adobe Reader has no apparent problems reading the PDF. pdfrw is currently not very fault tolerant.

Also, pdfrw works by being completely agnostic to the actual content of the PDF page you are placing. So for example, you wouldn't be able to use pdfrw inspect a page to see if it contains a certain string of text in the lower right-hand corner. However if you don't need to do anything like that you should be fine.

Upvotes: 2

dwelch
dwelch

Reputation: 3046

I'm currently using PyPDF to read, write, and combine existing PDF's and ReportLab to generate new content. Using the two package seemed to work better than any single package I was able to find.

Upvotes: 6

vartec
vartec

Reputation: 134581

There is an add-on for ReportLab — PageCatcher.

Upvotes: 1

Related Questions