Reputation: 2561
I have code that generates PDF for me.I am using FPDF to generate PDF.sometimes it gives out put but sometimes it behaves weirdly and it creates pdf with bad format so it doesnt open in any pdf reader.
moreover when it gives me bad format, size of pdf increases dramatically..
can anyone suggest what wrong is going with special cases..?
here is the code..
$pdf_Str = "<table border='1'>
<tr bgcolor=\"#666666\">
<td>Name</td>
<td>Number</td>
<td>Adjusted Amount</td>
<td>Invoice Date</td>
<td>Transaction Date</td>
<td>Amount</td>
<td>Balance</td>
<td>Record Type</td>
<td>Session</td>
<td>Course</td>
</tr>";
foreach($data as $row){
$pdf_Str .="<tr>
<td>".$row['student_name']."</td>
<td>".$row['invoiceNumber']."</td>
<td>".$row['invoiceAdjustedAmount']."</td>
<td>".($row['invoiceDate']!=''?$row['invoiceDate']:' ')."</td>
<td>".($row['TransactionDate']!=''?$row['TransactionDate']:' ')."</td>
<td>".($row['invoiceAmount']!=''?$row['invoiceAmount']:' ')."</td>
<td>".($row['invoiceBalance']!=''?$row['invoiceAmount']:' ')."</td>
<td>".($row['recordType']!=''?$row['recordType']:' ')."</td>
<td>".$row['sessionName']."</td>
<td>".($row['catalogName']!=''?$row['catalogName']:' ')."</td>
</tr>";
}
$pdf_Str .='</table>';
$p = new PDFTable();
$p->setfont('times','',12);
$p->htmltable($pdf_Str);//
$p->output("student_info.pdf",'I');
Upvotes: 0
Views: 2383
Reputation: 431
You could try http://code.google.com/p/dompdf/ there are plenty of HTML to PDF library's available and I have used the one for FPDF for creating invoices with complex tables, as long as the css is not too complex it usually renders fine.
I still find that using the FPDF library by itself produces better results when it comes to things like print ready PDF's you just need to put in the effort and sit there outputting the file inline hitting refresh while nudging elements around.
For the above you should be able to create some decent code using
$string = 'Name';
$border = 1;
$padding = 0;
$ln = 0;
$align = 'L';
$pdf->Cell($pdf->GetStringWidth($string)+$padding,3,0,'$align');
Put your header and data into an array and loop through swapping $ln to 2 at the end of each row, leave border as 0 until your happy with your output etc..
Upvotes: 0
Reputation: 4461
As far as I remember FPDF doesn't allow to convert html->pdf. You need to use its own functions(Cell(), MultyCell(), etc). But you could use library mPDF It is really great and very easy to use. It can convert html+css(!)->pdf. And it handles this job awesome. I recomend this library.
I hope it will be helpfull.
Upvotes: 1
Reputation: 26451
You can't create table in PHP. You have to use fpdf built-in function to do that.
Refer this : create table in pdf with wrap data using fpdf in php
and also Check this out it may help's you.
http://www.elated.com/articles/create-nice-looking-pdfs-php-fpdf/
Upvotes: 2