Friday, April 12, 2013

PHP: add a download as pdf file button in report page



In my last post, I created a button for convert and  download csv file
PHP: add a download as csv file button in report page
Now I want to add another button for download pdf file.In my report.php:
 <script>
function generatePdfA(){
   document.forms['getcsvpdf'].action = 'report_pdfA.php';
   document.forms['getcsvpdf'].submit();
}
</script>
       <form name="getcsvpdf" action="report_csvA.php" method="POST">
         <input type="submit" name="submit" value="Download CSV file" class="input-button" />
          <input type="submit" name="submitpdf" value="Download pdf file" class="input-button"  onclick="generatePdfA();" />
      </form>


For pdf file conversion, I use action report_pdf.php, which used tcpdf library to convert html table to pdf format.
 I  download tcpdf from
http://www.tcpdf.org/index.php

 and install tcpdf in current directory

 report_pdf.php code:

 <?php
require_once('./tcpdf/config/lang/eng.php');
require_once('./tcpdf/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);
// set document information
// set font
$pdf->SetFont('helvetica', 'B', 20);

// add a page
$pdf->AddPage();

$pdf->Write(0, 'CESEI Activity Reports for ACS', '', 0, 'L', true, 0, false, false, 0);

$pdf->SetFont('helvetica', '', 8);

$pdf->SetCreator(PDF_CREATOR);
$tbl = '
<table cellspacing="0" cellpadding="1" border="1">
<thead>
<tr>
      <th scope="col" width=35% style="text-align:left" >Type of Activity </th>
      <th scope="col"  style="text-align:left" >Number of Activity</th>
      <th scope="col" style="text-align:left">Hours of Instruction</th>
       <th scope="col" style="text-align:left" colspan="6">Surgeon, Physicians, Residents, Medical Students, Nurses, Allied Health Professionals</th>
</tr>
</thead>
<tr>
 <td> </td>  <td> </td>  <td> </td>
 <td> S</td>  <td>P </td>  <td>R</td> <td>MS</td>  <td>N</td>  <td>AHP</td>
 </tr>
 <tr>
 <td><b>Courses</b> </td>  <td> </td>  <td> </td>
 <td> </td>  <td> </td>  <td> </td> <td> </td>  <td> </td>  <td> </td>
 </tr>
 <tr><td>Simulators - High Fidelity</td><td>'.$_POST['count_sh'].'</td><td>'.
$_POST['count_hours_sh'].'</td><td>'.$_POST['count_s_sh'].'</td>
<td>'.$_POST['count_p_sh'].'</td><td>'.$_POST['count_r_sh'].'</td>
<td>'.$_POST['count_ms_sh'].'</td><td>'.$_POST['count_n_sh'].'</td>
<td>'.$_POST['count_ahp_sh'].'</td>
    </tr>
 
</table>';
$pdf->writeHTML($tbl, true, false, false, false, '');
$pdf->Output('activity_log_for_acs.pdf', 'I');
?>

Video: add a download as pdf file button in report page

 

6 comments:

  1. beautiful Very Help Full Thanks

    From
    Hariprasad1411@gmail.com

    ReplyDelete
    Replies
    1. Jiansen Lu'S Computing Blog: Php: Add A As Pdf File Button In Report Page >>>>> Download Now

      >>>>> Download Full

      Jiansen Lu'S Computing Blog: Php: Add A As Pdf File Button In Report Page >>>>> Download LINK

      >>>>> Download Now

      Jiansen Lu'S Computing Blog: Php: Add A As Pdf File Button In Report Page >>>>> Download Full

      >>>>> Download LINK CI

      Delete
  2. how to do for multiple rows meas (the whole list view) ? Please give me suggestion.

    ReplyDelete
  3. I want to get the multiple rows, I tried but didn't get the success. Please provide the solution.

    ReplyDelete
  4. Please converter website script downloads make in bloggers ok I hope you

    ReplyDelete
  5. Jiansen Lu'S Computing Blog: Php: Add A As Pdf File Button In Report Page >>>>> Download Now

    >>>>> Download Full

    Jiansen Lu'S Computing Blog: Php: Add A As Pdf File Button In Report Page >>>>> Download LINK

    >>>>> Download Now

    Jiansen Lu'S Computing Blog: Php: Add A As Pdf File Button In Report Page >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete