繁体   English   中英

TCPDF生成的PDF在Mac Preview和Safari上显示为空白

[英]TCPDF generated PDF shows blank on Mac Preview and Safari

但是在Google Chrome浏览器中打开时没有问题。 当我使用Safari /预览版打开它时,我得到了一个空白页。 放大/缩小没有任何作用。

以下是我用于生成PDF文件的代码:

require_once('../vendor/tecnickcom/tcpdf/tcpdf.php');

class MYPDF extends TCPDF {
    //Page header
    public function Header() {
        // get the current page break margin
        $bMargin = $this->getBreakMargin();
        // get current auto-page-break mode
        $auto_page_break = $this->AutoPageBreak;
        // disable auto-page-break
        $this->SetAutoPageBreak(false, 0);
        // set bacground image
        $img_file = '../assets/img/background.jpg';
        $this->Image($img_file, 0, 0, 150, 90, '', '', '', false, 150, '', false, false, 0);
        // restore auto-page-break status
        $this->SetAutoPageBreak($auto_page_break, $bMargin);
        // set the starting point for the page content
        $this->setPageMark();
    }
}

$pdf = new MYPDF('L', PDF_UNIT, [150, 90], true, 'UTF-8');

$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Kent');
$pdf->SetTitle('Title Here');
$pdf->SetSubject('Subject Here');
$pdf->SetTopMargin(44);
$pdf->setPrintFooter(false);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->SetFont('helvetica', '', 44);
$pdf->AddPage();
$pdf->writeHTML('This is the content.', false, false, false, false, 'C');
$pdf->Output(__DIR__ . '/output.pdf', 'F');

出现此问题的2个原因,首先请使用绝对路径,其次您的pdf也不会在Adobe acrobat中打开。 这是因为您的图像缺少icc配置文件。 打开您的照片,然后再次将其保存在Photoshop或类似软件中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM