Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

PDF vs. HTML for invoice generation

by Anonymous Monk
on Nov 24, 2010 at 18:51 UTC ( #873523=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

An application that I'm working on generates invoices that contain contact information for the client, as well as line items with pricing and a grid of pictures of each line item. The invoices will be sent to clients as PDFs. However, I'm unsure whether to generate PDFs natively in my application, or generate HTML that can then be converted to PDF by the end user by "printing" to PDF. The drawback that I see with generating PDFs natively is that the PDF modules I've seen seem pretty complicated; if I go with HTML I can create a fairly simple HTML::Template template, populate it from my database, and write the output in just a few lines.


Replies are listed 'Best First'.
Re: PDF vs. HTML for invoice generation
by moritz (Cardinal) on Nov 24, 2010 at 19:11 UTC
Re: PDF vs. HTML for invoice generation
by Illuminatus (Curate) on Nov 24, 2010 at 19:02 UTC
    The problem most companies have with using HTML for 'official' correspondence is that the rendering of HTML can vary, depending on the tool. PDF, on the other hand, always renders the same. For something like an invoice, companies usually want full control of the 'look and feel'.


Re: PDF vs. HTML for invoice generation
by chrestomanci (Priest) on Nov 24, 2010 at 21:36 UTC

    You may have read that I recently asked a question on PDF generation. My requirements are different from yours, in that I need precise placement of lots of graphics, where as you want mostly text, but we can probably share some of the same solutions.

    I would agree with you that the PDF modules are not easy to use. I also found them buggy, but then my needs are complex.

    After asking the question and reading the responses, I have decided to take the route of generating SVG using a template, and then converting the template to PDF using inkscape's svg2pdf tool. I think that solution might suit you as well.

    You can 'draw' your invoice in inkscape or suchlike, and get the layout just right complete with your company logo. You put random place holder text for where the invoice text will be. Once you have finished, you save the SVG, which will be easy to understand XML, and replace the place holder text with template tags. From there it should be fairly easy to feed the template into your favourite templating library, and convert the resultant SVG to PDF.

Re: PDF vs. HTML for invoice generation
by aquarium (Curate) on Nov 24, 2010 at 21:45 UTC
    since your source is a database, an alternative is going the whole hog, and get a report generator product suitable for your DB. Report generators have the capability to produce invoice and other summary reports, and can output in a variety of formats, including pdf usually. crystal reports is probably overkill and costly, but there are opensource alternatives. search for "report" in a opensource project repository.
    the hardest line to type correctly is: stty erase ^H
Re: PDF vs. HTML for invoice generation
by ikegami (Pope) on Nov 24, 2010 at 20:11 UTC
    Most mail programs have limited understanding of styling, if any. I'd go with attaching a PDF and providing a link to your web site where the receipt can be shown as HTML.
Re: PDF vs. HTML for invoice generation
by zwon (Abbot) on Nov 25, 2010 at 12:08 UTC

    I used Cairo to generate PDF. It is extremely fast and doesn't consume a lot of memory. It is not hard to use, but still you have to spend some time reading Cairo documentation.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://873523]
Approved by moritz
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-05-25 09:55 GMT
Find Nodes?
    Voting Booth?