Generate PDF from MySQL Data.

Asked By 0 points N/A Posted on -

I create a report using PHP. I use MySQL database here.

But now I want to generate a PDF report from it. I have no idea how to create the PDF report.

How can I make that PDF?


Exactly I want a PDF report from MySQL data.

Best Answer by AnnaAlexis
Best Answer
Best Answer
Answered By 0 points N/A #111530

Generate PDF from MySQL Data.


Create a connection with MySql through PHP.

Retrieve required data from database using queries.

After retrieving data from database, you will have to create a new PDF file.
$newPDF=PDF_new(); creates handle for new PDF document.

Then give name to the document:

Start a new page by using PDF_begin_page() function and similarly PDF_end_page() is used to end the page. PDF_show_xy() function is to write contents on PDF page at specified position.

Here you will pass the data you retrieved from databases. Do not forget to pass x and y positions. PDF_close () function is to close the PDF file. There are many other functions to add styles and formats.

You can use them to make your PDF report attractive.

Answered By 0 points N/A #111531

Generate PDF from MySQL Data.


Hello George,

You can use fpdf heaps to do just exactly that. Note that there are lots of extra codes that you can get to do things like rounded rectangles, ploygons and so forth.

The following class of code should help you generate PDF from MySQL data:

    $results = $chmdb->query("SELECT * FROM " . DB . "members WHERE active = 1");

    // Standard format
    $pdf = new PDF_Label('5160');

    // Print labels
    while($row = $results->fetch_object()) {
    $text = sprintf("%s %sn%s %sn%s %s, %s", "$row->first_name", "$row->last_name", "$row->address1",  "$row->address2", "$row->city", "$row->state", "$row->zip");

Hopefully this will help you generate PDF from the MySQL data.



Login/Register to Answer

Related Questions