3

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Josef
  • 59
  • 1
  • 9
  • Sounds like it would work, but whether there is a better way to do what you want depends on too many things to give a definitive answer. Are the XSLT files predefined in the system, or would users have to upload their own to do what they want? – halfer Jun 03 '12 at 11:04
  • For me, generating a report-style PDF is best done through a GUI tool in which you can design your sections. I've used Jasper and iReport for this, and it works very well indeed. Jasper offers a SOAP interface so you can kick it off using PHP. – halfer Jun 03 '12 at 11:06
  • Hi! Thanks for your comments! I've been looking at using Jasper as a reporting tool. But haven't thought of using it this way. But you're absolutely right. I don't need an XML source, I'll let them design a report template with the right parameters. Then accessing that report through a PHP SOAP client. I googled a bit and immediately got some good hits: http://jasperapiclient.googlecode.com/svn-history/r2/trunk/JasperApiClient.php Thank you very much for pointing me to the right direction. I would like to mark your comment as the right answer. Will you write an answer? – Josef Jun 03 '12 at 13:11
  • Josef, thanks - glad that's useful for you `:)`. – halfer Jun 03 '12 at 14:31

2 Answers2

0

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.

geon
  • 8,128
  • 3
  • 34
  • 41
  • Thanks for your answer. Halfer had a great idea by using Jasper reports and its SOAP client that will serve this perfectly. Thanks for your help! – Josef Jun 03 '12 at 13:13
0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186