Generating PDF file |
[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');
[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.
[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');
[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]
[eluser]PravinS[/eluser]
what is actual value of $attachment, is it a pdf file path or raw data
[eluser]ninjayan[/eluser]
A raw data. C0034539 and C03458349053 but only shows the last one.
[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 ;
[eluser]ninjayan[/eluser]
Thanks for the response. Is it possible to float the tables? thanks |
Welcome Guest, Not a member yet? Register Sign In |