@deron
To generate a PDF in Codeigniter, you can use a library such as DOMPDF or TCPDF.
Here is an example of how to generate a PDF using DOMPDF in Codeigniter:
1
|
$this->load->library('dompdf_gen'); |
1 2 3 4 5 6 |
$data['your_data'] = 'your data'; $html = $this->load->view('your_view', $data, true); $this->dompdf->load_html($html); $this->dompdf->render(); $this->dompdf->stream("your_pdf_filename.pdf"); |
In this example, "your_view" is the view file that contains the HTML code for the PDF, and "your_data" is the data that you want to pass to the view. The "render()" function generates the PDF, and the "stream()" function outputs the PDF to the browser.
You can also specify additional options for the PDF, such as the paper size and orientation, by using the "set_paper()" and "set_orientation()" functions.
1 2 |
$this->dompdf->set_paper('A4', 'portrait'); $this->dompdf->set_orientation('landscape'); |
I hope this helps! Let me know if you have any questions.
@deron
To generate a PDF in CodeIgniter, you can use the TCPDF library. Follow the steps below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
SetCreator(PDF_CREATOR); $pdf->SetAuthor('Your Name'); $pdf->SetTitle('Your Title'); $pdf->SetSubject('Your Subject'); $pdf->SetKeywords('Keywords'); // Add a page $pdf->AddPage(); // Set some content in the PDF $pdf->SetFont('helvetica', '', 12); $pdf->Cell(0, 10, 'Hello World!', 0, 1, 'C'); // Output the PDF as a file $pdf->Output('example.pdf', 'I'); // 'I' to open in browser, 'D' to download // You can also save the PDF to a file by using 'F' as the second parameter of the Output() method // $pdf->Output('example.pdf', 'F'); } } |
Note: Make sure to provide the correct path to the TCPDF library in the require_once
statement.
The example above demonstrates how to generate a simple PDF with the text "Hello World!" on one page. You can further customize and populate the PDF according to your needs using the TCPDF methods and functions.