Create Link to generate PDF File


Good day!

I have a query to display data from my database.
Here is my code:

    $query3 = "SELECT employee_no, arabic_name, fullname, nationality, join_date, passport_no, passport_end_date, res_no, res_end_date, company_work, company_sponsor 
    FROM tbl_employee_informations WHERE res_end_date = '$date_visa' ORDER BY res_end_date";
$res = $conn->query($query3);
    $cnt = $res->num_rows;
echo"<a href=\"expiring_visa_pdf.php\" target=\"_Blank\" style='float:left;margin:auto auto 10px auto;font-weight:bold;text-decoration:none; color:#8d735a;'>Generate PDF<a/>";
    echo "<p style='float:left;margin:auto auto auto 350px;font-weight:bold; color:#8d735a;'>Total: $cnt </p>";
    echo "<div id='report_one'>";
    echo "<table style='border-radius:3px; border: 1px solid #a6a6a4;'>";
    echo "<tr style='text-align:center;font-weight:bold; background-color:#FFF;'>";
    echo "<th class='report_table'>EMPLOYEE NO.</th>";
    echo "<th class='report_table'>ARABIC NAME</th>";
    echo "<th class='report_table'>ENGLISH NAME</th>";
    echo "<th class='report_table'>NATIONALITY</th>";
    //echo "<th class='report_table'>JOIN DATE</td>";    
    echo "<th class='report_table'>PASSPORT NO.</th>";
    //echo "<th class='report_table'>PASSPORT END DATE</th>";
    echo "<th class='report_table'>RESIDENCY ID</th>";
    echo "<th class='report_table'>RESIDENCY END DATE</th>";
    echo "<th class='report_table'>COMPANY WORK</th>";
    echo "<th class='report_table'>COMPANY SPONSOR</th>";
    echo "</tr>";
while($row = $res->fetch_assoc())
    $employee_no = $row['employee_no'];
    $fullname = $row['fullname'];
    $fullname = utf8_encode($fullname);
    $arabic_name = $row['arabic_name'];
    $nationality = $row['nationality'];
    $join_date = $row['join_date'];
    $join_date = date('d-m-Y',strtotime($join_date));
    $passport_no = $row['passport_no'];
    $passport_end_date = $row['passport_end_date'];
    $passport_end_date = date('d-m-Y',strtotime($passport_end_date));
    $res_no = $row['res_no'];
    $res_end_date = $row['res_end_date'];
    $res_end_date = date('d-m-Y',strtotime($res_end_date));
    $company_work = $row['company_work'];
    $company_sponsor = $row['company_sponsor'];
    echo "<tr>";
    echo "<td class='report_table'>$employee_no</td>";
    echo "<td class='report_table' dir='RTL'>$arabic_name</td>";
    echo "<td class='report_table'>$fullname</td>";    
    echo "<td class='report_table'>$nationality</td>";    
    //echo "<td class='report_table'>$join_date</td>";
    echo "<td class='report_table'>$passport_no</td>";    
    //echo "<td class='report_table'>$passport_end_date</td>";
    echo "<td class='report_table'>$res_no</td>";
    echo "<td class='report_table'>$res_end_date</td>";
    echo "<td class='report_table'>$company_work</td>";
    echo "<td class='report_table'>$company_sponsor</td>";
    echo "</tr>";

echo "</table>";
echo "</div>";

Now, I need to convert this table form html to pdf once I click the Generate PDF.

I don’t know how to do that.

I started by this:


class PDF extends FPDF
// Page header
function Header()
    // Logo
    // Arial bold 15
    // Move to the right
    // Title
    $this->Cell(30,10,'Expiring Visa');
    // Line break

// Page footer
function Footer()
    // Position at 1.5 cm from bottom
    // Arial italic 8
    // Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');

// Instanciation of inherited class
$pdf = new PDF();
  //  $pdf->Cell(0,10,'Printing line number '.$i,0,1);


but in this code I can only show the logo and title

I hope someone can help me on this matter.

Thank you.

I think you’d need to run the query again and instead of displaying the results, use the various fpdf functions to place the data in your PDF file. Or maybe if it won’t place too much of a strain on the server, generate the PDF at the same time as you generate the html, so the link is just to download it rather than to generate it on the fly.

Aren’t there any examples on the fpdf site that you can work through?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.