I'm going to create an invoice system, I am preparing for that now. I'm gonna use Codeigniter. The thing is that I want to create invoice in PDF so I can send it through email.
What is your guys advice? I was thinking of HTML to PDF conversion, Or Show the invoice on screen and install a pdf printer (when you hit print and you choose to print to a PDF file) Or create a word document and connect to the MySQL server I think with odbc.
Any of you guys have experience with this?
This question is related to
php
codeigniter
pdf
TCPDF is PHP class for generating pdf documents.Here we will learn TCPDF integration with CodeIgniter.we will use following step for TCPDF integration with CodeIgniter.
Step 1
To Download TCPDF Click Here.
Step 2
Unzip the above download inside application/libraries/tcpdf.
Step 3
Create a new file inside application/libraries/Pdf.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once dirname(__FILE__) . '/tcpdf/tcpdf.php';
class Pdf extends TCPDF
{ function __construct() { parent::__construct(); }
}
/*Author:Tutsway.com */
/* End of file Pdf.php */
/* Location: ./application/libraries/Pdf.php */
Step 4
Create Controller file inside application/controllers/pdfexample.php.
<?php
class pdfexample extends CI_Controller{
function __construct()
{ parent::__construct(); } function index() {
$this->load->library('Pdf');
$pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle('Pdf Example');
$pdf->SetHeaderMargin(30);
$pdf->SetTopMargin(20);
$pdf->setFooterMargin(20);
$pdf->SetAutoPageBreak(true);
$pdf->SetAuthor('Author');
$pdf->SetDisplayMode('real', 'default');
$pdf->Write(5, 'CodeIgniter TCPDF Integration');
$pdf->Output('pdfexample.pdf', 'I'); }
}
?>
It is working for me. I have taken reference from http://www.tutsway.com/codeignitertcpdf.php
I've used dompdf with some success before. Although it can be a bit fussy about malformed HTML and there are still some CSS methods that aren't supported (e.g. css float does not work).
Download the package from github, and place it into a folder called dompdf
in your application/thirdparty
directory.
You can then create a helper with some functions to use the dompdf library, here is an example:
dompdf_helper.php
:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename='', $stream=TRUE)
{
include APPPATH.'thirdparty/dompdf/dompdf_config.inc.php';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
if ($stream) {
$dompdf->stream($filename.".pdf", array("Attachment" => 0));
} else {
return $dompdf->output();
}
}
You simply pass the pdf_create
method your HTML as a string, the filename for the pdf file it will generate, and then an optional thirdparameter. The third parameter is a true/false flag to determine if it should save the file to your server before prompting the user to download it or not.
I have used mpdf in my project. In Codeigniter-3, putted mpdf files under application/third_party and then used in this way:
/**
* This function is used to display data in PDF file.
* function is using mpdf api to generate pdf.
* @param number $id : This is unique id of table.
*/
function generatePDF($id){
require APPPATH . '/third_party/mpdf/vendor/autoload.php';
//$mpdf=new mPDF();
$mpdf = new mPDF('utf-8', 'Letter', 0, '', 0, 0, 7, 0, 0, 0);
$checkRecords = $this->user_model->getCheckInfo($id);
foreach ($checkRecords as $key => $value) {
$data['info'] = $value;
$filename = $this->load->view(CHEQUE_VIEWS.'index',$data,TRUE);
$mpdf->WriteHTML($filename);
}
$mpdf->Output(); //output pdf document.
//$content = $mpdf->Output('', 'S'); //get pdf document content's as variable.
}
Create new pdf helper file in application\helpers folder and name it pdf_helper.php. Add below code in pdf_helper.php file:
function tcpdf()
{
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
}
?>
For more Please follow the below link:
http://www.ccode4u.com/how-to-generate-pdf-file-in-codeigniter.html
I've used MPDF library. For more information view this tutorial https://arjunphp.com/generating-a-pdf-in-codeigniter-using-mpdf/
Source: Stackoverflow.com