Reputation: 454
I have a search form wherein it allows PDF download whenever you enter a search query on it. The problem here is that I can only download the PDF if there are only few numbers of result..
If result exceeds 80 records, it displays a blank page..
Please Advice, Thanks.!
here's my code:
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// add a page
$pdf->AddPage();
$pdf->Write(0, $order_type, '', 0, 'L', true, 0, false, false, 0);
$pdf->SetFont('helvetica', '', 7);
// -----------------------------------------------------------------------------
ob_start();
if(!($query = mysql_query($this->sql)))
throw new Exception(mysql_error());
if(($field_name=mysql_num_fields($query)) > 0) {
$tableheader = '<table>';
$tableheader .= '<tr>';
$tableheader .= '<td>Rows</td>';
for($x=0;$x<$field_name;$x++) {
$tableheader .= '<td>'.mysql_field_name($query,$x).'</td>';
if($x==10)
break;
}
$tableheader .= "</tr>";
}
if(mysql_num_rows($query)) {
$row = 1;
while($field = mysql_fetch_assoc($query)) {
if($row == 1) {
echo $tableheader;
}
echo "<tr>";
echo "<td>{$row}</td>";
foreach($field as $val) {
echo "<td>{$val}</td>";
}
echo "</tr>";
if($row==85) {
break;
}
$row++;
}
echo "</table>";
}
$html = ob_get_contents();
ob_end_clean();
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
// -----------------------------------------------------------------------------
//Close and output PDF document
$pdf->Output("memberdata.pdf", 'I');
Upvotes: 2
Views: 3499
Reputation: 93
I know this is an old question, but for people who get here by googling, add this at the beginning of your code:
// Increase max_execution_time. If a large pdf fails, increase it even more.
ini_set('max_execution_time', 180);
// Increase this for old PHP versions (like 5.3.3). If a large pdf fails, increase it even more.
ini_set('pcre.backtrack_limit', 1000000);
The report generation dies because of a preg_replace() used by TCPDF. It was a PHP bug for older versions (mine is 5.3.3), preg_replace() returns null silently when the string is too long. See this:
http://sourceforge.net/p/tcpdf/discussion/435311/thread/f7f96b04
Upvotes: 2