Question

I've used a couple of days to think of a best practice to generate a PDF, which end users can customize the layout for themselves. The PDF output needs to be saved on the server or sent back to the PHP file so the PHP file can save it, and the PHP file needs to know that it went OK.

I thought the best way to do this was to use XML, XSLT and Apache Cocoon. But I'm not sure if this is possible or if it's a good idea since I can't find any information of people doing anything similar. It cannot be an uncommon problem.

The idea came when I read about Cocoon converting XML through XSLT to PDF:

http://cocoon.apache.org/2.1/howto/howto-html-pdf-publishing.html

and being able to take in variables:

http://old.nabble.com/how-to-access-post-parameters-from-sitemap-td31478752.html

This is what I had in mind:

  1. A php file gets called by a user, the php file generates a source XML file with a specific name
  2. The php file then makes a request to Cocoon (on the same web server) to apply the user defined XSLT on the XML file. A parameter will be needed here to know which XSLT to apply.
  3. The request is handled by the PHP file and then saved as a PDF on the server, and can later be mailed away.

Will this work at all? Is there a better way to handle this?

The core problem is that the users need to be able to customize the layout on the PDFs themselves, and I need the server to save the PDF and to mail it later on. The users will use it for order confirmations, invoices, etc. And I wouldn't like to hard code the layout for each user.

Was it helpful?

Solution

I've had some good results in the past by setting up JasperReports Server and creating reports using iReport Designer. They're both available in F/OSS ("community") editions, though you can pay for support and value-adds if you need those things.

This was a good solution for us, since we could access it via the Java API for our Java system, and via SOAP for our PHP system. The GUI designer made tweaking reports very easy for non-technical business staff too.

OTHER TIPS

I use webkithtml2pdf to generate my PDF:s. Just create a document with HTML and CSS for printing like you would usually do, the run it through the converter.

It works great for generating things like invoices. You can use SVG for logos and illustrations, and they will look great in print since they are vector based. Even rounded corners with dotted outlines works perfectly.

A minor gotcha is that the input html must have th htm or html file name suffix, so you can't use the default tempfile functions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top