SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Addict lmasi02's Avatar
    Join Date
    Aug 2004
    Location
    Zambia
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    creating pdf documents with php

    Hi All,

    Anyone with a sample code i can use to create a PDF invoice on the fly using php.

    KR,
    Power of Knowledge

  2. #2
    SitePoint Zealot
    Join Date
    May 2004
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've used both dompdf and fpdf successfully for pdf generation.

  3. #3
    SitePoint Addict lmasi02's Avatar
    Join Date
    Aug 2004
    Location
    Zambia
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Warboss_Alex View Post
    I've used both dompdf and fpdf successfully for pdf generation.
    Kindly advise how it works
    Power of Knowledge

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    With FPDF you copy the library from their site and then follow the instructions on what to call to do what part of tthe setting up of your PDF. There are also a collection of additional functions people have written to perform more specialised tasks.

    http://www.fpdf.org/

    dompdf appears to work the same way (I haven't tried that one) - http://www.digitaljunkies.ca/dompdf/
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Zealot
    Join Date
    May 2004
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    dompdf appears to work the same way (I haven't tried that one) - http://www.digitaljunkies.ca/dompdf/
    Yep, pretty much. From their site:

    PHP Code:
    <?php
    require_once("dompdf_config.inc.php");

    $html =
      
    '<html><body>'.
      
    '<p>Put your html here, or generate it with your favourite '.
      
    'templating system.</p>'.
      
    '</body></html>';

    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
    $dompdf->stream("sample.pdf");

    ?>
    I presume in your case you'd generate a simple invoice with an HTML table or something and use it for the $html var.

  6. #6
    PHP/Rails Developer Czaries's Avatar
    Join Date
    May 2004
    Location
    Central USA
    Posts
    806
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've worked extensively with both libraries for generating invoices for InvoiceMore, and the two options don't work the same way at all. DOMPdf is used to generate a PDF from HTML/CSS code. FPDF generates PDFs with PHP functions and commands. You're comparing apples and oranges here.

    I love the idea of DOMPdf, because it means I only have to make ONE invoice template for both printing and PDFs (just HTML/CSS). However, it doesn't really work in practice. It's extremely slow. At times, generating PDF invoices with DOMPdf took in excess of 1 minute. If I tried to do a batch generation of PDF invoices, the script would just timeout. I removed the timeout limit, but then I ran into memory issues, even after increasing the memory limit to 128M. It was clear that for my purposes, DOMPdf just wasn't going to work.

    I switched to FPDF, and while I did have to create a duplicate template with PHP code instead of HTML code to build the same thing, it's very fast. An invoice with the same exact visual result takes about a second to generate, enabling me to make on-demand PDF invoices available to my customers. I've also never had a problem with batch PDF generation, and I don't have to increase the memory limit or execution time either. In addition to that, the PDF end result is actually a smaller filesize as well.

    There are some plugins for FPDF that do convert some limited HTML to PDF formatting, but it's nowhere near as robust as DOMPdf's HTML and CSS support, so I just don't use them. Either way you go, it's a lot of tedious manual work to get the PDFs looking just right.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Czaries View Post
    the two options don't work the same way at all.
    The way you use both products (which is what was being discussed) is the same - in both cases you download the library and follow the instructions on their site on how to incorporate the library into your code.

    What they do is what is different not how you use them. So you do work with them the same way (of course using whichever one does what you are trying to do).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    PHP/Rails Developer Czaries's Avatar
    Join Date
    May 2004
    Location
    Central USA
    Posts
    806
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    The way you use both products (which is what was being discussed) is the same - in both cases you download the library and follow the instructions on their site on how to incorporate the library into your code.

    What they do is what is different not how you use them. So you do work with them the same way (of course using whichever one does what you are trying to do).
    I disagree. That's like saying all boxed software works the same because you buy it in a box and read the instructions to install it. The distribution may be the same, but the product is very different. You can't say both libraries work the same just because both libraries can be downloaded and have instructions that you read. That's ridiculous.

    They are two very different PDF generation libraries, that aim to solve the PDF generation problem two completely different ways. They are not the same at all.

    I think this is a case of mixed-up terminology: The way you 'use' both products is completely different. The way you 'get' both products is the same. There's a huge difference.

  9. #9
    SitePoint Member robinthomas's Avatar
    Join Date
    Apr 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used TCPDF and it was working fine for me.

  10. #10
    SitePoint Addict
    Join Date
    Aug 2007
    Location
    St. Louis, MO.
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see allot of people talk about ezpdf. This is usually my preference.

  11. #11
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    United Kingdom
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We have started using HTMLDOC for HTML to PDF conversion, with some success. It's nice and fast which is definitely it's plus point over DOMPDF. However it does have a rather limited HTML support.

  12. #12
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,014
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    There is the R&OS PDF library, it was featured on the 1st edition of the PHP Anthology (a sitepoint book) so it might well be PHP4, as I have not tried it, i don't know how easy it will be to upgrade it to PHP5, but in its favour the PHP Anthology lists the R&OS PDF library as being open source.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  13. #13
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    from http://framework.zend.com/manual/en/zend.pdf.html

    The Zend_Pdf component is a PDF (Portable Document Format) manipulation engine. It can load, create, modify and save documents. Thus it can help any PHP application dynamically create PDF documents by modifying existing documents or generating new ones from scratch. Zend_Pdf offers the following features:

    Create a new document or load existing one.

    Retrieve a specified revision of the document.

    Manipulate pages within a document. Change page order, add new pages, remove pages from a document.

    Different drawing primitives (lines, rectangles, polygons, circles, ellipses and sectors).

    Text drawing using any of the 14 standard (built-in) fonts or your own custom TrueType fonts.

    Rotations.

    Image drawing.

    Incremental PDF file update.
    Have not used it yet myself however.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  14. #14
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    With FPDF you copy the library from their site and then follow the instructions on what to call to do what part of tthe setting up of your PDF. There are also a collection of additional functions people have written to perform more specialised tasks.

    http://www.fpdf.org/

    dompdf appears to work the same way (I haven't tried that one) - http://www.digitaljunkies.ca/dompdf/
    DOMPdf chokes on quite a few things, Generating from an API using db data is still the best way, so yes fpdf or tcpdf is my preference for those things.

    I have found HTML to PDF converters to be dicy at best. Small wonder if you consider what people are expecting them to do. It takes browser makers years to properly support the newest HTML features to everyone's satisfaction. Nobody should expect a PHP solution to replicate a modern HTML/CSS layout perfectly in PDF.
    Visit my blog
    PHP && Life
    for technology articles and musings.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •