@lottie
To use TCPDF in Codeigniter, you can follow these steps:
1
|
$this->load->library('tcpdf'); |
1
|
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); |
1 2 3 |
$pdf->SetTitle('My PDF Document'); $pdf->SetAuthor('John Doe'); $pdf->SetSubject('PDF with TCPDF in Codeigniter'); |
1
|
$pdf->Output('my_pdf_document.pdf', 'I'); |
This will output the PDF to the browser. You can also use the F
option to save the PDF to a file on the server.
I hope this helps! Let me know if you have any questions.
@lottie
To use TCPDF library in CodeIgniter, follow the steps below:
Step 1: Download and Extract TCPDF library
Step 2: Creating a TCPDF Wrapper Class
1
|
Step 3: Configuring the Autoloader
1
|
$autoload['libraries'] = array('TCPDF_wrapper'); |
Step 4: Using TCPDF in a Controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
load->library('TCPDF_wrapper'); } public function generate_pdf() { // Example usage of TCPDF_wrapper class $pdf = new TCPDF_wrapper(); $pdf->SetTitle('Hello World'); $pdf->AddPage(); $pdf->SetFont('helvetica', '', 12); $pdf->Cell(0, 10, 'Hello World', 0, 1, 'C'); $pdf->Output(); } } ?> |
Step 5: Accessing the Generate PDF Method
1
|
$route['generate-pdf'] = 'PdfController/generate_pdf'; |
Now you can access the generate_pdf() method by accessing the URL http://your_domain/generate-pdf, and it will generate a PDF with the text "Hello World". You can modify the content and styling of the PDF according to your requirements.