2016-07-28 76 views
0

但在Google Chrome中打開時沒有問題。當我用Safari/Preview打開它時,我得到了一個空白頁面。放大/縮小不做任何事情。TCPDF生成的PDF在Mac Preview和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'); 

回答

0

兩個原因這個問題,首先請使用絕對路徑,其次您的PDF不以Adobe Acrobat或者打開。這是因爲你的圖像缺少icc配置文件。打開你的照片並將其保存在Photoshop或類似的軟件中。