Search code examples
phppdfodt

PHP PDF template library with PDF output?


Is there any PHP PDF library that can replace placeholder variables in an existing PDF, ODT or DOCX document, and generate a PDF file as the end result, without screwing up the layout?

Requirements:

  • Needs no 3rd party web service

  • Ability to run on shared web hosting would be ideal (no binary installations / packages required)

Mind you, a library that is able to load an existing PDF file and insert text programmatically at a specific position is not enough for my use case.

As far as my research shows, there is no library that can do this:

  • TCPDF can only generate documents from scratch

  • FPDI can read existing PDF templates, but can only add contents programmatically (no template variable replacement)

  • There are various DOCX/ODT template libraries out there but they don't output PDF

PHPDOCx claims to be able to do exactly what I need - but they don't offer a trial version and I'm not going to buy a cat in a bag, especially not when there seems to be no other product on the web that does this. I find it hard to believe they can do this without problems - if you have successfully done this using the product, please drop a line here.

Am I overlooking something?

Is there a way to do this using PDF forms? I am creating the source documents in OpenOffice 3.

I may be able to use standard Linux commands (pdftk is available for example, trying that out right now.)

Update: *Argh!* I was called out of the office and the bounty expired in the meantime. Starting a new bounty: As far as my testing shows, no solution works for me perfectly yet.

Update II: I will be looking the pdftk approach soon, but I am also starting another bounty for one more round of collecting additional input. This question has now seen 1300 rep points in bounties, must be some kind of a record :)


Solution

  • Pekka,

    I looked in to this previously, I think you can use pdftk (a command line utility), to fill in a PDF form using FDF/XFDF data files, which you could easily generate from within PHP. That was the best option I've seen so far, though there may well be a native library.

    pdftk is quite useful in general, worth having a look at.

    Update: Have a look here: http://php.net/manual/en/book.fdf.php