Forum How do I...?

Template Driven PDF Generation

sanderson02
Hello,
I'm trying to evaluate PrinceXML for our team's use and after skimming through a lot of the documentation, I have some questions. What I had envisioned going in to this was the ability to define an HTML template that could have some placeholder elements, and pair it up with some data to be filled in and generate a PDF. Our use case is to provide structured PDF documents to our users that fill in data based on their selections. For example, their name, address, and potentially a dynamically sized list of medications.

The reason we are looking for something that is more template driven is that we will have several layouts per customer that we'll need to produce documents for off of the same dataset. User A might qualify for a document that displays in one manner, while User B might qualify for a document that displays in a slightly different manner.

I haven't quite seen that Prince can be used with templates. It seems to me that I would have to design a step before PDF generation that would do the HTML template population first, and produce a filled HTML document that could then be passed in to Prince for PDF generation. Am I correct, or is it possible to do something more template driven?
mikeday
Yes that is correct, there are many different ways (hundreds?) of doing HTML templates: PHP is basically a template language, there are template libraries for JavaScript and Ruby and Python and .NET and there are dozens of programs for generating webpages based on different templating systems.

Prince itself takes the final HTML that comes out of the template system and converts that (using CSS) to PDF, so it can be used with any template system capable of generating HTML.
hallvord
Prince also supports JavaScript and the XMLHttpRequest, so if your data comes from some API that can be reached with an XHR request, you could use JS.

Announcement: repos for tests/utils

hallvord
(Which Mike already mentioned of course ;) )

Announcement: repos for tests/utils