使用TCPDF生成具有选定值的PDF

时间:2019-05-08 02:39:30

标签: php pdf tcpdf

所以我想做的是有一个按钮,该按钮将生成数据库中单个表的所有数据的PDF文件,现在我试图生成仅具有选定值的pdf文件。最近,我添加了一个“输入类型= datetime-local”,而我想做的基本上是,我有两个具有起始和结束日期的datetime-locals,并且只会在给定日期之间生成PDF。

现在这是棘手的部分,数据库中的“ dateTime”列的格式为(YEAR / MONTH / DAY:Hours:Mins:Seconds),本地日期时间的格式为(DAY / MONTH / YEAR :Hours:Mins:AM / PM)。我听说不建议在您的数据库中添加时间戳,但是我处于无法再更改数据库的情况。

下面是“生成PDF”代码,可打印所有数据

 }  
 if(isset($_POST["generate_pdf"]))  
 {  

 require_once('tcpdf/tcpdf.php');  
      $obj_pdf = new TCPDF('L', 'mm', 'LETTER', true, 'UTF-8', false);
      $obj_pdf->SetCreator(PDF_CREATOR);  
      $obj_pdf->SetAuthor('Nicola Asuni');
      $obj_pdf->SetSubject('TCPDF Tutorial');
      $obj_pdf->SetKeywords('TCPDF, PDF, example, test, guide');
      $obj_pdf->SetTitle("Incident Report");  
      $obj_pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);  
      $obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));  
      $obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));  
      $obj_pdf->SetDefaultMonospacedFont('helvetica');  
      $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);  
      $obj_pdf->SetMargins(2, '7', PDF_MARGIN_RIGHT, '10');  
      $obj_pdf->setPrintHeader(false);  
      $obj_pdf->setPrintFooter(false);  
       $obj_pdf->setPrintFooter(false);
      $obj_pdf->SetFont('helvetica', '', 5);  
      $obj_pdf->AddPage();  

      date_default_timezone_set("Asia/Manila");
      $content = '';  
        $content2 = date("F d, Y h:i:s A",mktime());
      $content .= '
      <h4 align="center">Incident Report</h4> <br /> 

      <table align="center" border="1" cellspacing="0" cellpadding="3">  
           <tr>  

                <th width="8%">School</th>  
                <th width="5%">Grade/Level</th> 
                 <th width="6%">Section</th> 
                <th width="7%">Date and Time</th>  
                <th width="6%">Incident Type</th>  
                <th width="7%">Incident Description</th>
                   <th width="6%">Sender</th>  
                <th width="10%">Person Involved</th>   
                   <th width="14%">Students that tagged safe</th> 
                   <th width="14%">Students that tagged unsafe</th> 
                      <th width="4%">Male Count</th> 
                      <th width="5%">Female Count</th> 
                   <th width="5%">Number of involved people</th>
                  <th width="5%">Attachment</th>
           </tr>';  
      $content .= fetch_data();  
      $content .= '</table>';  


      $obj_pdf->writeHTML($content);  
      $obj_pdf->writeHTML($content2);
      $obj_pdf->Output('report.pdf', 'I');  
 }  
 ?>  

下面是日期时间本地代码

         <label >Date From: </label>
 <input type="datetime-local" name="bday" max="3000-12-31" 
        min="1000-01-01" class="form-group">
         <label >Date To:</label>
 <input type="datetime-local" name="bday" min="1000-01-01"
        max="3000-12-31" class="form-group">

有人要告诉我该怎么办以及应该如何处理?我应该使用其他dateTime选择器吗?还是我应该坚持我拥有的东西。任何答案将不胜感激。谢谢!

0 个答案:

没有答案