Results 1 to 2 of 2

Thread: Create Link to generate PDF File

  1. #1
    Join Date
    Oct 2011

    Create Link to generate PDF File


    Good day!

    I have a query to display data from my database.
    Now I display it in web page, but I need also to create a link to generate pdf file same as the web page display
    Here is my code:
    PHP 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;
    "<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/>";
    "<p style='float:left;margin:auto auto auto 350px;font-weight:bold; color:#8d735a;'>Total: $cnt </p>";
    "<div id='report_one'>";
    "<table style='border-radius:3px; border: 1px solid #a6a6a4;'>";
    "<tr style='text-align:center;font-weight:bold; background-color:#FFF;'>";
    "<th class='report_table'>EMPLOYEE NO.</th>";
    "<th class='report_table'>ARABIC NAME</th>";
    "<th class='report_table'>ENGLISH NAME</th>";
    "<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>";
    "<th class='report_table'>RESIDENCY END DATE</th>";
    "<th class='report_table'>COMPANY WORK</th>";
    "<th class='report_table'>COMPANY SPONSOR</th>";
    $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'];
    "<td class='report_table'>$employee_no</td>";
    "<td class='report_table' dir='RTL'>$arabic_name</td>";
    "<td class='report_table'>$fullname</td>";    
    "<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>";
    "<td class='report_table'>$res_end_date</td>";
    "<td class='report_table'>$company_work</td>";
    "<td class='report_table'>$company_sponsor</td>";

    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.

  2. #2
    Join Date
    Jul 2013
    Voorheesville NY USA
    FPDF is a really good pdf creation tool that I have used for several years. It does however take a bit of learning to see how to organize the necessary calls to the different functions and make your output look the way you want.

    You have to envision your output (pdf) page as a set of rows and columns. Those are managed in FPDF as x and y values. You can set the height of each row in your document, set the font size, and then position the 'cursor' at a certain x/y coordinate and use the Cell or MultiCell function to output some data. By setting the width of each cell you can then make successive calls to Cell/MultiCell to output other items on the same 'row' and eventually use the Ln function to move to the next row. Basically you have to lay out your planned document and then use a loop to call a function that makes all your output calls for each row of data.

    A bit of a learning curve but once you get the knack it gets pretty easy. I would begin by reading thru the help to see what the different functions can do. You can also find some good help on their website.

    PS - almost forgot. You state that your code only shows you the header and footer. Of course! You commented out any other output you wanted to generate.
    Last edited by ginerjm; 08-25-2015 at 11:03 AM.
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');

    at the top of ALL php code while you develop it!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles