我正在使用CakePHP 2.4上的TCPDF查看pdf文件以进行打印。 除了Adobe Acrobat阅读器之外,所有浏览器都会打印完全相同的预期结果。唯一的例外是FireFox!它添加了一个额外的空白页面。我在这里(和那里)尝试了其他问题中提到的所有建议的解决方案,但都没有。
这是我的代码:
<?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();
我看到的问题:
Extra blank page with TCPDF
how TCPDF prevent the extra blank page
Firefox prints extra blank page
答案 0 :(得分:0)
我发现没有文档,没有文章,没有人可以解释这种奇怪的行为。 毕竟,额外的空白纸不会造成任何伤害!