Generate PDF from MySQL Data.

Asked By 0 points N/A Posted on -
qa-featured

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.

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

Generate PDF from MySQL Data.

qa-featured

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:
PDF_open_file($newPDF,”Report.pdf”);

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 10 points N/A #111531

Generate PDF from MySQL Data.

qa-featured

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');
    $pdf->Open();


    // 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");
    $pdf->Add_PDF_Label($text);
    }
    $pdf->Output();

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

Regards,

Carl

Related Questions