0

I'm working on automating our company invoicing system. Currently all data is stored in our local MySQL database and someone manually updates an excel spreadsheet and then merges this data into a MS Word template. The goal is to automate this process so that the invoice can be generated from our intranet website as a PDF.

My original plan was to create a template in HTML/CSS and use wkhtmltopdf to generate the PDF but I ran into problems with getting a repeatable header and footer on each page. thead and tfoot aren't supported by Webkit and the fix suggested in this other question does not seem to work either.

So I then stumbled on using XML and XSL-FO, the latter I know nothing about. Is this the best path to take? Are there any libraries or utilities out there that will make converting my HTML+CSS into XML+XSL-FO easier? Are there any other alternatives I'm overlooking?

EDIT

Currently the server is CentOS Linux with a MySQL database. All other code is currently in PHP currently but that may change as the whole system is being revamped. Linux and MySQL will almost certainly remain, though.

Community
  • 1
  • 1
Corey D
  • 4,689
  • 4
  • 25
  • 33
  • 1
    put "pdf creator library" in google and start evaluating the options that suit your needs. – Mark Schultheiss Feb 22 '12 at 21:16
  • You could use Zend Frameworks PDF class. http://framework.zend.com/manual/en/zend.pdf.html I used this once as a test case for making our company's specification sheets. You basically just lay things out on a grid system, where I believe the top left was 0,0. You can then plan out a 8.5x11" page and design your invoice. ZF classes can be used independently of the whole system. Then again, you'll need a PHP system. – jmbertucci Feb 22 '12 at 21:18
  • Something like CutePDF, if you want to stick with the word template. Or if you are feeling a bit brave something like iText or iTextSharp – Tony Hopkinson Feb 22 '12 at 21:19
  • 3
    What development language are you using and what are your development constraints? – Shan Plourde Feb 22 '12 at 21:21
  • What is your server environment like? – Dave Feb 22 '12 at 21:24
  • About "CSS+XHTML to PDF" technologies, see [Why use XSL-FO instead of CSS2, for transform HTML into good PDF?](http://stackoverflow.com/q/10641667/287948) question and answers. – Peter Krauss Jul 26 '12 at 19:33

4 Answers4

4

For your requirement, XSL-FO might just do the trick. It is much cleaner to produce the pdf's directly from the data, then going the cumbersome html path, unless you need to display the html as well, then you might consider converting from html to pdf, but it will always be messy.

You can get xml results from mysql quite easily (mysql --xml) and then you write one (or several) xsl-fo stylesheet for the data. then, you cannot only produce pdfs, but also postscript files or rtf's with some processors.

XSL-FO has its limitations tho, but for your situation, it should suffice.

I admit, the learning curve can be steep, and maintaining xslt-stylesheets can get very tiring, but as you start knowing more about it, you end up writing less code.

another possibility is to do the whole thing in e.g. java or c# - send select statements and loop the results and iteratively build the pdf using a library like iText.

mindandmedia
  • 6,800
  • 1
  • 24
  • 33
1

You could try JODReports or Docmosis as less-code intensive options. You supply Word or OpenOffice Writer documents to act as templates and use these engines to manipulate/populate the templates then spit out the documents in the format(s) you require. This may mean your existing Word-templates can be used directly which should save you some effort/time.

iText is another library that will let you build and pump out PDFs from code. It's pretty good.

Paul Jowett
  • 6,513
  • 2
  • 24
  • 19
  • This is essentially what I found after doing some more research. Will probably be using the ruby [ODF-Report library](https://github.com/sandrods/odf-report). Don't know why I didn't think of this earlier :) – Corey D Feb 23 '12 at 15:53
0

If you cloud use ASP.NET for web you can use free ReportViewer library and designer for automated of publishing PDF-s. Here is some references:
http://gotreportviewer.com

http://weblogs.asp.net/srkirkland/archive/2007/10/29/exporting-a-sql-server-reporting-services-2005-report-directly-to-pdf-or-excel.aspx

adopilot
  • 4,340
  • 12
  • 65
  • 92
0

If you're OK using .NET and C#, you could use DotPdf from Atalasoft (obligatory disclaimer: I work for Atalasoft and wrote most of DotPdf). The Generating namespace is geared for exactly what you're trying to do: automate report generation. From the very basics, you could just create docs directly with the toolkit or you can create template documents that have unpopulated text fields that you can reload and fill later (see here and here for examples).

plinth
  • 48,267
  • 11
  • 78
  • 120