Generating a PDF invoice directly from my php and mysql website

Posted on 2006-05-15
Last Modified: 2008-08-19
Hi Everybody,

I've got a webshop where customers can buy certain items.
The items they order are stored as an order in a MySQL database.

I would like to generate an PDF invoice directly from the site and email it.

(hit button --> get data from mysql --> generate pdf --> email to customer)

The site is hosted by an external party.

I hope somebody's got an idea.

Thanx in advance

Question by:Geerd
    LVL 16

    Assisted Solution

    LVL 2

    Expert Comment

    Easy to use, well documented.
    HINT: do not forget to install the font directory when you use it, it got me for an hour :)
    LVL 16

    Expert Comment

    >> it got me for an hour :)
    easy indeed :P
    LVL 2

    Accepted Solution

    Well, this is one of these things that you download, unzip and upload .. and
    I didn't take the time to read the documentation (VERY well done).
    I was just trying to share the fact that I came accross the same problem, when I was starting scripting in PHP and this was a life saver at the time.
    pdf-php remains in my toolbox since then ..
    Here is an example:

    require "class.ezpdf.php"; // PHP-PDF Class

    $doc =& new Cezpdf('letter'); // choice of format
    $doc->ezImage("logo.jpg","","","none"); // insert score logo
    $doc->ezText("<b>Application for: ".$question1.".".$question3.".".$question2."</b>",9,array("justification"=>"center")); // name of the applicant
    $doc->ezNewPage(); // Next Page
    // Creates files ouput to avoid Internet Explorer Bug
    // The page called has an .php extension and the stream output
    // has a .pdf extension. IE does not take the file back for display.
    $pdfcode = $doc->ezOutput();
    $dir = "pdf_files";

    if (!file_exists($dir)) {
    mkdir ($dir,0777);
    $fname = './'.$dir.'/'.$question1.'.pdf';
    $fp = fopen($fname,'w');
    $delay = '0';

    LVL 16

    Expert Comment


    now to the second part, the questioner want to send that PDF via email

    you can use almighty phpMailer tool to do that. get it here

    when u save that PDF to a file, add that file as an attachment to the email and when mail is sent, delete the generated PDF file unlink(file_path)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now