Generating PDF file - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Generating PDF file (/showthread.php?tid=58387) |
Generating PDF file - El Forum - 06-09-2013 [eluser]ninjayan[/eluser] Hello to everyone. I want to generate a pdf with a data coming from the database. I tried using html2pdf but the problem is I don't know how to output the data from database and arrange it on the pdf. Anyone can suggest a good and simple pdf generator? Thanks Code: $this->load->library('html2pdf'); Generating PDF file - El Forum - 06-09-2013 [eluser]PravinS[/eluser] try TCPDF refer: http://www.tcpdf.org/ Generating PDF file - El Forum - 06-10-2013 [eluser]ninjayan[/eluser] Hello. Thanks for the response. By any chance, do you have a sample view and controller? thanks --- Update Please see my controller function for the tcpdf http://pastebin.com/dV8rByE4 $table = <<<EOD EOD; syntax error on my text editor. Generating PDF file - El Forum - 06-10-2013 [eluser]PravinS[/eluser] don't create library to use tcpdf, use helper, so you will be able to use tcpdf class as it is. in controller load helper as $this->load->helper('tcpdf_helper'); and in view use tcpdf code as tcpdf(); $obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $obj_pdf->SetCreator(PDF_CREATOR); $obj_pdf->SetTitle(''); $pdf_title = ""; $obj_pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pdf_title, PDF_HEADER_STRING); $obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $obj_pdf->SetDefaultMonospacedFont('helvetica'); $obj_pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $obj_pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $obj_pdf->SetFont('helvetica', '', 9); $obj_pdf->setFontSubsetting(false); $obj_pdf->AddPage(); ob_start(); <!-- YOUR HTML CODE --> $content = ob_get_contents(); ob_end_clean(); $obj_pdf->writeHTML($content, true, false, true, false, ''); $obj_pdf->Output('output.pdf', 'I'); Generating PDF file - El Forum - 06-10-2013 [eluser]ninjayan[/eluser] Hello. Thank you for the response. The data I want to print comes from database with only one column named 'linked_document' and is in array format. It returns only 1 record which should be 2. [code] foreach ($attachments as $row) { $attachment = $row->linked_document; } </code] Generating PDF file - El Forum - 06-10-2013 [eluser]PravinS[/eluser] what is actual value of $attachment, is it a pdf file path or raw data Generating PDF file - El Forum - 06-10-2013 [eluser]ninjayan[/eluser] A raw data. C0034539 and C03458349053 but only shows the last one. Generating PDF file - El Forum - 06-10-2013 [eluser]PravinS[/eluser] i think you will not need any PDF conversion library, try using php header to display the PDF raw data like this in view $output = YOUR_RAW_DATA; header('Content-type: application/pdf'); echo $output ; Generating PDF file - El Forum - 06-11-2013 [eluser]ninjayan[/eluser] Thanks for the response. Is it possible to float the tables? thanks |