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 10:03 AM.
    PS - If you're posting here you should be using:

    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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.09863 seconds
  • Memory Usage 2,876KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (2)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates