Welcome Guest, Not a member yet? Register   Sign In
Generating PDF file
#1

[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');
   $this->html2pdf->folder('./uploads/');
   $this->html2pdf->filename('test.pdf');
   $this->html2pdf->paper('A4', 'portrait');
   $this->html2pdf->html("<h1>Some Title</h1><p>Some content in here</p>");
   $this->html2pdf->create('download');
#2

[eluser]PravinS[/eluser]
try TCPDF

refer: http://www.tcpdf.org/
#3

[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.
#4

[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();

&lt;!-- YOUR HTML CODE --&gt;

$content = ob_get_contents();
ob_end_clean();
$obj_pdf->writeHTML($content, true, false, true, false, '');
$obj_pdf->Output('output.pdf', 'I');
#5

[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]
#6

[eluser]PravinS[/eluser]
what is actual value of $attachment, is it a pdf file path or raw data
#7

[eluser]ninjayan[/eluser]
A raw data.
C0034539 and C03458349053 but only shows the last one.
#8

[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 ;
#9

[eluser]ninjayan[/eluser]
Thanks for the response. Is it possible to float the tables? thanks




Theme © iAndrew 2016 - Forum software by © MyBB