SitePoint Sponsor

User Tag List

Results 1 to 23 of 23
  1. #1
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How to create a PDF using a PHP library?

    Good day,

    Could you please recommend any free PHP library to create PDF files?
    I have a website for selling books made with HTML, PHP and CSS. After a customer selected some books (and have them in the cart), I'd like to generate a PDF quotation showing all selected books and the total.

    Thanks a lot!!

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)

  3. #3
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks again!!

  4. #4
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi Pullo,

    I have read Dompdf information.

    Could you please confirm what exactly I have to do here to download the library?

    Navigate to wherever you want to put the library and execute:
    Code:
    git clone https://github.com/dompdf/dompdf.git
    git submodule init
    git submodule update
    Thanks a lot!!!

  5. #5
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Are you familiar with using GIT?
    If not, just navigate here and hit "Download ZIP" button

  6. #6
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi try this http://www.mpdf1.com/mpdf/index.php,it's easy to use...

  7. #7
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi Pullo,

    I downloaded it. I also discovered how to unpack the ZIP file in cPanel, so I have the library there.

    Thanks a lot!!!

  8. #8
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot, I'll check it in case I cannot work with Dompdf.

  9. #9
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Yay!
    It might also be worth having a look at jemz solution, too, especially if he can recommend it.

    Edit:

    I see you beat me to it

  10. #10
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi Pullo,

    I started reviewing the documentation of this product.
    After making a test .php file with the first sample code and open it with a browser, I get a missing file warning message for dompdf-master/lib/php-font-lib/classes/Font.php, from dompdf-master/dompdf_config.inc.php on line 332.

    Checking dompdf_config.inc.php, lines 330 - 333 are:

    if (DOMPDF_ENABLE_AUTOLOAD) {
    require_once(DOMPDF_INC_DIR . "/autoload.inc.php");
    require_once(DOMPDF_LIB_DIR . "/php-font-lib/classes/Font.php");
    }

    But when checking dompdf inner directories, within php-font-lib there is nothing, so the error message is right, there is no classes directory nor font.php file there.
    Looking the whole dompdf directory, there is no classes directory nor font.pdf file at all.

    Any idea of what am I doing wrong?
    Thanks a lot!!!

  11. #11
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    Sorry that you didn't get on with the tutorial I linked to.

    Did you try mPDF as @jemz ; suggested?

    Maybe it would be better if you tell us what you are trying to achieve in a little more detail, then we can consider what the best solution might be.

  12. #12
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi Pullo,

    In the meantime I was able to find the missing files.
    I am now in testing process.

    This is I'd like to do:
    We have an online bookstore. The idea is after the customer selected the books and put them in the cart, to be able to generate a simple PDF quotation showing a quotation number, customer name and e-mail (requested in a previous page), selected books and the total.

    Thanks a lot!!

  13. #13
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Sir_Arcturua View Post
    In the meantime I was able to find the missing files.
    I am now in testing process.
    Good stuff.
    Let us know if you run into any problems

  14. #14
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot. Based on my requirements, is DomPDF the right tool?

    Also, do you know any basic tutorial?

  15. #15
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Sir_Arcturua View Post
    Thanks a lot. Based on my requirements, is DomPDF the right tool?
    Yes. It's a library for generating a PDF from HTML markup and CSS styles (

    Quote Originally Posted by Sir_Arcturua View Post
    Also, do you know any basic tutorial?
    I thought the SitePoint one I linked to was pretty basic.
    I just followed it in 5 minutes and was able to get the basic example working with no problems.

    Where are you getting stuck?

    Also, check Google for more tutorials: https://www.google.de/search?q=dompdf+tutorial

  16. #16
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi Pullo,

    Once again, thanks a lot for so much help.

    I just followed it in 5 minutes and was able to get the basic example working with no problems.
    I am feeling like a Neanderthal

    I am still thinking like PHPMailer, where the idea is to build the final e-mail step by step with instructions.
    What is the basic strategy with this library? I guess I have to build a webpage of what I want as a PDF outcome. I do not see any instruction to build the PDF step by step.

    I have this basic file:
    Code:
    <?php
    require_once("../dompdf-master/dompdf_config.inc.php");
    
    $file= file_get_contents('http://www.libromania.cl/spanish/home_spanish.shtml');
    
    $dompdf = new DOMPDF();
    $dompdf->load_html($file);
    $dompdf->render();
    $dompdf->stream("sample.pdf");
    
    ?>
    Please open http://www.libromania.cl/spanish/test_pdf.php to see the result.
    What am I going wrong?

    Thanks again!!!

  17. #17
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    Your approach seems fine to me.

    The first thing I would look at is whether your page is valid.
    If you run it through the W3C validator you get 7 errors.
    I would fix these first and see if it helps the situation.

  18. #18
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi Pullo,

    Thanks a lot.

    I am reviewing the errors.
    The first one is about "No Character Encoding Found".
    Researching, the suggested code for Latin America is ISO-8859-01. I have added it using two available instructions:
    Code:
            <meta charset="ISO-8859-01">
            <meta http-equiv="content-type" content="text/html; charset=ISO-8859-01">
    It looks well with Internet Explorer, but not with Firefox, please see the page. Characters with accents are not recognized: http://www.libromania.cl/spanish/hom...ish_test.shtml


    Without any character encoding instruction, website is working well. Why should I use one?
    Also, can you see if the one I am trying to use is the right one and what am I doing wrong?

    Thanks a lot!!!

  19. #19
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi Pullo,

    Please dismiss part of my last post. Website characters are ok with character encoding ISO-8859-1.

    Running W3C validator for my test page (http://www.libromania.cl/spanish/hom...sh_test.shtml), now I get 26 errors and 2 warning.

    Without any character encoding instruction, website is working well. Why should I use one?
    Before start modifying my website trying to fix errors, could you please confirm if this is the right character encoding for me to use? (for Spanish Latin America).

    Thanks a lot!!

  20. #20
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,153
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    I find UTF-8 works well for most languages

    But things will get messy if you don't use it everywhere.

    Try losing the "0" i.e.
    ISO-8859-1

  21. #21
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi Mittineague,

    Thanks, I had corrected the zero.
    Do you mean I should use UTF-8 instead of ISO-8859-1?

  22. #22
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,153
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    If ISO-8859-1 is working OK then it would probably be more work than it's worth to change everything over - the HTML, your test editor, the database etc.

    I just find it easier and less problematic to use UTF-8 for everything (don't have to remember or look up entity values for a rarely used character)

  23. #23
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Hey Sir_Arcturua,

    How did you get on with correcting the errors?
    I just ran the page through the validator and found 22 of them.

    Is there anything you need help with?


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
  •