Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP PDF template library with PDF output? [closed]

Tags:

php

pdf

odt

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

like image 382
Pekka Avatar asked Dec 11 '10 12:12

Pekka


1 Answers

This is not very practical, but for completeness: If you already have an ODT template, then you might very well retain that as template. Modifying the OpenDocument content.xml and replacing placeholders therein is pretty simple. If so, you could use unoconv or pyodconverter to transform the ODT into a final PDF.

unoconv -f pdf -o final.pdf template.odt 

Very obviously this requires a full OpenOffice setup (UNO and Writer) on the webserver. And obviously not every webhoster would go with that! haha. Even if it's simple on any Debian or Fedora setup. The execution speed would probably not be stellar either. But then it might be the cleanest approach, since OOo governs both formats way better than any PHP class ever could.

like image 62
mario Avatar answered Sep 20 '22 00:09

mario