views:

4152

answers:

21

Our company is looking to integrate invoices into a new system we are developing.

We require some a solution to create a layout of the invoice and then convert to pdf.

We have considered just laying out the invoice in html/css then converting to pdf. We have also considered using SVG->PDf conversion.

Both of these solutions integrate well into our existing templating language used for our web application.

Historically we have been a Microsoft based business and used Crystal Reports for such a task but we are looking an open source Linux solution for this project.

Does any one have any suggestions of an approach or technology we could use for such a task?

A: 

This html-2-pdf site may be a helpful starting point: http://maarten.lippmann.us/?p=101

A site a friend of mine built uses a script to churn HTML pages into printable PDFs, too - http://philambdaupsilon.org. Not sure on the exact details of it, but he is an SO user, and I'll send this question to him, too.

warren
+8  A: 

Try this... create a blank invoice with Word (or whatever you want) and save it as a PDF.

Then use a PDF library to modify the PDF (insert the text at particular coordinates). We do this in the Microsoft world and it is extremely easy.

The biggest benefit is that we can use our own tools to create and modify the template. If we want to add some static text, we just crank open Word, make the change and save it to a PDF file (that is being used as a template).

For Microsoft, we use iTextSharp which is actually a C# port of the original Java version of iText


Additionally...

You can use Adobe Acrobat to insert fields in the PDF (address, phone, invoice number, line item 1, line item 2, etc...) and then use iText/iTextSharp to populate these fields at run time.

This is, in more detail, what we do... and it is extremely easy.

Jason
Modifying PDF applications like that is going to be a huge pain because of the way PDF files are structured. Each element has a fixed position and there is no 'reflow' thingamajari that lets you adjust the content while preserving the layout.
Jasper Bekkers
@Jasper - if we are talking about invoices, it is not that hard. You know what coordinates you can enter text, and you usually only want one line at a time. BTW... I updated with another idea.
Jason
Ah yes, didn't consider the use-case too much probably. The reason I avoid generating PDF files like that is because it wouldn't have worked out in a contract management system which would've had to pull all kinds of stunts to get good looking text.
Jasper Bekkers
Do you have a sample code for how to edit the template pdf ? thx
metro
+5  A: 

I've previously produced invoices by templating a PostScript file, and then using Ghostscript's ps2pdf to convert those into PDFs.

Alnitak
+1 - Postscript isn't all that hard to generate. In a pinch you can look at the output from a DTP or drawing program.
ConcernedOfTunbridgeWells
Well, yes, but I crafted all mine by hand ;-)
Alnitak
A: 

Unfortunately, the best system on the market (at present) is passing the HTML & CSS to a ColdFusion server and have that return the rendered PDF. So if money isn't a big concern, this is the quickest to deploy solution that'll render the best results.

I've tried very hard to get FPDF, TCPDF, the R&OS pdf class, and even CodeIgniter's recommendation to work, but nothing with stable output for anything beyond the most basic/bland HTML files.

Honestly, if the ColdFusion solution isn't viable, I'd use html2ps, and then ps2pdf to convert your files into a PDF.

(This is all assuming that you don't want to take the time and design each PDF using the native PDF-creator code in PHP. This is what systems like SugarCRM use. Though its very functional with stable results, the actual creation of each PDF-generator file is a most painful process)

Eric Caron
+5  A: 

We use Reportlab with Python. If you look around there are a load of ready-made forms/invoices/etc.

Ali A
A: 

Not sure what your goal is here, but there is an opensource php-library called fpdf, which also has an extension for taking a pre-made pdf as layout and then populate it with more content, generating a new PDF with that info.

However, I would go for a solution that you can integrate nicely into the plattform you're building, but I wouldn't go in a HTML->PDF solution since you won't have any clue about what would fit on a piece of paper regarding sizes in that kind of enviroment, meaning you won't know when you should split the content into two separate templates.

jishi
+1  A: 

Probably the most flexible solution is to create XMLs with invoice data and then by using XSLTs transform the, into PDFs, HTMls, whatever...

It is not easy to get precision formatting done with xslt (and xsl-fo).
Stephan Eggermont
+2  A: 

It depends on your environment. If you have access to Java, you might look at iText (http://www.lowagie.com/iText/), a library that allows you to generate PDF files on the fly.

joel.neely
+8  A: 

The normal way is to install (La)TeX (probably already on the linux box) and run pdflatex to get the pdfs. You can also use Apache FOP, if you prefer xslt and xsl-fo.

If the number of invoices to create is low you might want to use open-office (directly or as a toolkit).

If you want high-precision positioning and low-level access, a low-level pdf library (I don't know if iTextSharp works with mono) might be what you want.

I would try out LaTeX first, because it allows you to get results with the least effort.

Stephan Eggermont
FOP, XSLT and XSL-FO is overkill for this, they are a nightmare. (IMHO)
Jason
A: 

We have used Jasper Reports before. It's not what you'd call user-friendly, but it will talk directly to your database.

Airsource Ltd
+2  A: 

There are several OSS reporting engines (Jasper Reports, Pentaho and BIRT to name three) that you could use in much the same way as you have historically used Crystal Reports. One of the other posters mentions ReportLab, which is an option if you're using Python or can embed a Python runtime in your application.

ConcernedOfTunbridgeWells
A: 

html2pdf works very well. You can use this to generate both HTML and PDF reports from the same source.

geocar
A: 

I'm fiddling with Black Sheep Invoices right now, which is great at first but now I'm having trouble actually getting it to render the PDFs. Lots of installation difficulties--probably a lot easier on your own server but i'm up on a shared host with it. The HTML output and data management portions are well done though, which is something you won't get out of just creating a postscript template. I was hoping to find a reference to a library that has an active development team though (Black Sheep is not being updated at this time).

Sleep Deprivation Ninja
A: 

If you want browser perfect HTML converted to PDF then try commandlineprint

You'll need to install firefox on a linux distro, disable all firefox alerts and then run it through a virtual display. Check this thread for more details.

It's infuriating to get running well but does give you the best results for HTML to PDF conversion I've seen.

rojoca
A: 

OK, a search of Google Code projects turned up Simple Invoices, which is awesome and well maintained.

Sleep Deprivation Ninja
Now, I'm not as impressed as I was at first. Even though they have great installation documentation, they don't make it clear how to delete the sample data or change the admin account information o_0
Sleep Deprivation Ninja
A: 

You might also try using XSL:FO. XSL:FO is a documented standard for describing page layout: http://www.w3.org/TR/xsl/#fo-section.

I've had success on two projects creating documents by creating an XML schema that defines the content of the "PDF". I then use the XSD tool (from Microsoft) to generate a class representing this document. I then map my data into that structure, serialize the populated class to XML, along with an XSL stylesheet that defines how that data should be mapped into FO, and pass it to an FO formatter. For formatters, I have use Alt-Soft's Xml2Pdf with success. There are a few others out there. There are some tools available to help create the XSL to FO stylesheet (i.e. stylusstudio and XmlSpy), but I recommend learning the FO constructs as the tools seem to produce bloated stylesheets. FO is comparable to HTML (where a P tag is a BLOCK tag in FO), but can be tricky. This nice thing about FO, is that some formatter support conversion to other formats, such as Word, HTML, etc.

Other options:

  1. iTextSharp (C# port of iText). Just started reading about this. Open source and free. I don't think there is any "templating" supported with this, but I could be wrong about that.

  2. SQL Server Reporting Services. Assuming your invoice data is in, or can be put in, a format that can be read by reporting services (SQL Server, Web Service, etc), define the layout in SSRS and then publish to reporting server. Use SSRS Web Services or query parameter execution to execute the report and have it output as PDF.

Brian
+1  A: 

There are two steps, if i understood correctly:
1) Creation of PDF template with placeholders to populate data programmatically
2) Populating the PDF template programmatically during run time

For #1, OpenOffice allows creation of PDF templates, which can then be populated programmatically. It's good enough to create simple invoices that doesn't probably involve datagrid/table kind of stuff.

For #2, you already have the answers here - iText, iTextSharp.

Hope this helps!

pencilslate
I am currently using Open Office to create the original PDF templates, and then using iTextSharp to programmatically insert data into the form fields. I set the border of the fields to not be visible, so users can't tell it is a text field!
SkippyFire
A: 

I use TROFF for my invoices because of its extremely simple textual encoding. The logic is a few lines of Perl. Keeping it simple.

Niels Castle
A: 

I love wkhtmltopdf http://code.google.com/p/wkhtmltopdf/

Anna
A: 

For a Ruby solution, try Prawn: http://prawn.majesticseacreature.com/

Randomibis
A: 

I use open office on the server and then generate the XML for the document (just unzip the document and hack away)

MathGladiator