4

I'm well aware that there are a billion questions relating to Python and PDF but none (that I can find) handle a fairly simple use-case.

I have a PDF template with some text in some places. I want to:

  • Open this PDF in Python
  • Replace a few known strings with other strings.
  • Save the edited version as a new file.

Currently the only option I can see is generating the whole PDF from scratch which is not very desirable because the template is a fairly complicated design that I'd have to re-implement somehow.

Is there not a library that can edit PDFs?

Oli
  • 235,628
  • 64
  • 220
  • 299
  • Reading PDFs is much harder than writing them, which is why your use case isn't well represented. I think there's a way to merge two PDF files which might work for you. – Mark Ransom Dec 22 '11 at 04:40
  • @MarkRansom Yes, I've seen a thread about that here. It's not ideal for me because I'd like to use the design of the PDF so that I don't have to reformat and position things in an open canvas. If I'm going that far, it's easier for me to just render a HTML page to PDF. – Oli Dec 22 '11 at 05:09
  • Is your template something you can have in an OpenOffice document? Even if you don't want to create a PDF from scratch, I think it's worth looking at [relatorio](http://relatorio.openhex.org/wiki/QuickExample). – jcollado Dec 22 '11 at 07:44

0 Answers0