File manager - Edit - /home/custbahd/mediagepr.com/admin/articles/print_pdf.php
Back
<?php function generateRow(){ $contents = ''; include_once('db/connection.php'); $sql = "SELECT * FROM articles"; //use for MySQLi OOP $query = $conn->query($sql); while($row = $query->fetch_assoc()){ $contents .= " <tr> <td>".$row['id']."</td> <td>".$row['title']."</td> <td>".$row['description']."</td> <td>".$row['topic']."</td> <td>".$row['editor']."</td> <td>".$row['image']."</td> </tr> "; } //////////////// //use for MySQLi Procedural // $query = mysqli_query($conn, $sql); // while($row = mysqli_fetch_assoc($query)){ // $contents .= " // <tr> // <td>".$row['id']."</td> // <td>".$row['firstname']."</td> // <td>".$row['lastname']."</td> // <td>".$row['address']."</td> // </tr> // "; // } //////////////// return $contents; } require_once('tcpdf/tcpdf.php'); $pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetTitle("Articles PDF"); $pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING); $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $pdf->SetDefaultMonospacedFont('helvetica'); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetMargins(PDF_MARGIN_LEFT, '10', PDF_MARGIN_RIGHT); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->SetAutoPageBreak(TRUE, 10); $pdf->SetFont('helvetica', '', 11); $pdf->AddPage(); $content = ''; $content .= ' <h2 align="center">Articles PDF</h2> <h4>Articles Table</h4> <table border="1" cellspacing="0" cellpadding="3"> <tr> <th width="5%">ID</th> <th width="20%">Title</th> <th width="30%">Description</th> <th width="20%">Topic</th> <th width="20%">Editor</th> <th width="20%">Image</th> </tr> '; $content .= generateRow(); $content .= '</table>'; $pdf->writeHTML($content); $pdf->Output('articles.pdf', 'I'); ?>
| ver. 1.4 |
Github
|
.
| PHP 8.1.33 | Generation time: 3.6 |
proxy
|
phpinfo
|
Settings