Question

I am viewing pdf files for printing, using TCPDF on CakePHP 2.4. All browsers print exactly the same expected results, in addition to Adobe Acrobat reader too. The only exception is FireFox! It adds an additional blank page. I tried all suggested solutions mentioned in other questions here (and there), and none worked.

Here is my code:

    <?php

App::import('Vendor', 'xtcpdf');
header('Content-type: application/pdf');
//see tcpdf_config.php for constants definitions
$pdf = new XTCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', FALSE);
// set margins
$PDF_MARGIN_LEFT = $PDF_MARGIN_TOP = $PDF_MARGIN_RIGHT = $PDF_MARGIN_BOTTOM = 0;
$pdf->SetMargins($PDF_MARGIN_LEFT, $PDF_MARGIN_TOP, $PDF_MARGIN_RIGHT, $PDF_MARGIN_BOTTOM);
$pdf->setPrintHeader(FALSE); //$pdf->SetHeaderMargin(25);
$pdf->setPrintFooter(FALSE); //$pdf->SetFooterMargin(25);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->setFontSubsetting(FALSE);
$pdf->SetAutoPageBreak(TRUE, 0);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->addPage('L', 'Letter');
//****************** Completion Image *************************************//
$pdf->Image('/img/completion.png', $x = -10, $y = 34, $w = 240, $h = 30, $type = 'PNG', $link = '', $align = 'C', $resize = TRUE, $dpi = 900, $palign = 'C', $ismask = false, $imgmask = false, $border = 0, $fitbox = TRUE, $hidden = false, $fitonpage = TRUE);

//************************************************** TITLE Body **************************************************//
$pdf->SetFont('times', '', 20);
$title = $information['title'] ;
$pdf->writeHTMLCell($w = 0, $h = 0, $x = 0, $y = 66, $title, $border = 0, $ln = 0, $fill = 0, $reseth = true, $align = 'C', $autopadding = true);

//****************** Description *********************************//
$pdf->SetFont('times', 'I', 16);
    $description = 'bla bla bla bla bla';
    $pdf->writeHTMLCell($w = 0, $h = 0, $x = 0, $y = 93, $description, $border = 0, $ln = 0, $fill = 0, $reseth = true, $align = 'C', $autopadding = TRUE);


//************************** NAME **********************************//
$pdf->SetFont('times', 'B', 24);
$fullName = $information['Student']['first_name'] . ' ' . (!empty($information['Student']['middle_initial']) ? ($information['Student']['middle_initial'] . ' ') : '') . $certificate['Student']['last_name'];
$pdf->writeHTMLCell($w = 0, $h = 0, $x = 0, $y = 127, $fullName, $border = false, $ln = 0, $fill = 0, $reseth = true, $align = 'C', $autopadding = FALSE);

//***************** Line/OFFICE ************************//

$pdf->SetFont('times', 'B', 12);
$office = '__________________________________________________<br/> Bla Bla Bla <br/>Office of bla bla blat<br/>bla bla bla bla';
$pdf->writeHTMLCell($w = 0, $h = 0, $x = 3, $y = 151, $office, $border = 0, $ln = 10, $fill = 0, $reseth = FALSE, $align = 'C', $autopadding = FALSE);

//******************************* Certificate No. ************************************//
$pdf->SetFont('times', 'B', 10);
$certNo = 'No. ' . $information['Certificate']['certificate_No'];
$pdf->writeHTMLCell($w = 0, $h = 0, $x = 32, $y = 154, $certNo, $border = 0, $ln = 0, $fill = 0, $reseth = FALSE, $align = 'L', $autopadding = false);

//*************************** Date of Issuance ****************************//
$pdf->SetFont('times', '', 10);
$issueDate = 'Date of Issuance: ' . date('F, Y', strtotime($information['Certificate']['award_date']));
$pdf->writeHTMLCell($w = 0, $h = 0, $x = 31, $y = 157, $issueDate, $border = 0, $ln = 0, $fill = 0, $reseth = false, $align = 'L', $autopadding = FALSE);
echo $pdf->Output('PDF' . $information['Certificate']['certificate_number'] . '.pdf', 'I');
$pdf->endPage();

questions I looked at: Extra blank page with TCPDF how TCPDF prevent the extra blank page Firefox prints extra blank page

Was it helpful?

Solution

I found no documentation, no articles, no one can explain such weird behavior. After all, an extra blank paper won't do any harm!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top