Very New to Codeigniter need help - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Very New to Codeigniter need help (/showthread.php?tid=66564) Pages:
1
2
|
RE: Very New to Codeigniter need help - Xaruf - 07-29-2020 I don't know if the problem is still relevant. First you have to download the domPdf folder in the libraries folder. Then you have to create a php class at the root of the libraries folder. Then you have to create a view that will receive the data to display in pdf. Then you create a function in the controller of your choice in which you call the model which will allow you to fetch your data in bdd to then transmit them to your view. I put the minimum code for it to work. To display the images in the view, you must not use the base_url () function of the url helper but use the php variable $ _SERVER ['DOCUMENT_ROOT'] This code works fine. I am French so sorry if my English is not correct /** * your personal class which will instantiate the dompdf library */ <?php defined('BASEPATH') OR exit('No direct script access allowed'); require 'dompdf/autoload.inc.php'; use Dompdf\Dompdf; class Pdf extends Dompdf { public function __construct() { parent::__construct(); $dompdf = new Dompdf(); } } /** * your fonction in the ctrl */ public function showBill($billID, $toDown) { $billDatas = $this->bills_model->get($billID); $datas = array( 'infos' => "PDF bill creation", 'title' => "Bill - ".$this->config->item('appName'), 'description' => "PDF bill creation", 'keywords' => "Facture", 'billDatas' => $billDatas ); // load your view in variable $pageHTML = $this->load->view('billpdf', $datas, true); $fileName = $billDatas['beneficiaryDetails']['beneficiaryName']."-"; $fileName = $fileName.$billDatas['beneficiaryDetails']['beneficiarySurname']."_"; $fileName = $fileName.$billDatas['billInfos']['billRef']."_"; $fileName = $fileName.$billDatas['billInfos']['billPeriod']; // load the dompdf library through your class $this->load->library('pdf'); // load the view with dompdf $this->pdf->loadHtml($pageHTML); // I put in comments what is optional // $customPaper = array(0,0,570,570); // $this->pdf->set_paper($customPaper); // $this->pdf->setPaper('A4','portrait');//landscape $this->pdf->render(); // il $toDown = 1 -> download file, if = 0 show in navigator $this->pdf->stream($fileName, array('Attachment' => $toDown)); } /** * the view */ <!DOCTYPE html> <html> <head> <title><?php //echo $title;?></title> <meta charset="utf-8"> <style>/* here you can place your css code */ html{ padding-top: 0px; margin-top: 0px; } body{ padding: 0px; margin: 0px; } table{ width: 100%; border-collapse: collapse; } .../... </style> </head> <body style="position: relative;"><?php /* create your html normally */ ?> <div backtop="10mm" backleft="10mm" backright="10mm" backbottom="20mm" id="zonePage" style="margin-top: 10px; padding-top: 0px; min-height: 100vh; display: flex; flex-direction: column;"> <div style="flex-grow: 1;"> <table id="tableCrt" style="margin-top: 0px;"> <tr id="trCrt1" style="height: 75px;"> <td id="tdCrt1_1" style="height: 75px;width: 25%;"> <img style="position: absolute; top: 10px; left: 0px; height: 130px" src="<?php echo $_SERVER['DOCUMENT_ROOT']."/assets/images/logos/logo2-240x147.jpg";?>"> </td> <td id="tdCrt1_2" style="height: 75px;width: 50%;"></td> <td id="tdCrt1_3" style="height: 75px;width: 25%;"> <img style="height: 75px;" src="<?php echo $_SERVER['DOCUMENT_ROOT']."/assets/images/logos/logo2-240x203.jpg";?>"> </td> </tr> <tr id="trCrt2" style="height: 115px;"> <td id="tdCrt2_1" style="width: 25%; padding-top: 75px;"> <span style="font-size: 1.15rem;"><?php echo $billDatas['infosEnterprise']['name'];?></span> <span style="font-size: 1.15rem;"><?php echo $billDatas['infosEnterprise']['adress'].'<br>'; ?></span> <span style="font-size: 1.15rem;"><?php echo $billDatas['infosEnterprise']['cp'].' '; ?></span> <span style="font-size: 1.15rem;"><?php echo $billDatas['infosEnterprise']['city'].'<br>'; ?></span> <span style="font-size: 1.15rem;"><?php echo $billDatas['infosEnterprise']['phone'].'<br>'; ?></span> <span style="font-size: 1.15rem;"><?php echo $billDatas['infosEnterprise']['email'].'<br>'; ?></span> <span style="font-size: 1.15rem;"><?php echo $billDatas['infosEnterprise']['siren']; ?></span> </td> <td id="tdCrt2_2" style="width: 30%;"></td> <td id="tdCrt2_3" style="width: 55%;"> <span style="font-size: 1.10rem;"><?php echo 'Periode: '.$billDatas['billInfos']['billPeriod'].'<br>'; ?></span> <span style="font-size: 1.10rem;"><?php echo 'Bill N°: '.$billDatas['billInfos']['billRef'].'<br>'; ?></span> <span style="font-size: 1.10rem;"><?php echo $billDatas['infosEnterprise']['city'].',the '.$billDatas['billInfos']['factDateEdition']; ?></span> </td> </tr> </table> <page_footer style="bottom: 10px;"> <p>...footer infos...</p> </page_footer> </div> </div> </body> </html> |