使用TCPDF从HTML生成带有图形的PDF

时间:2015-04-10 12:01:42

标签: php tcpdf

我正在使用TCPDF从HTML生成PDF。我的页面中有内容+图表。我可以下载内容但无法以PDF格式获取图形图像。我使用谷歌图表。它没有保存为图像,所以我转换为PNG。现在我的图表正在加载为PNG,但是当我尝试下载PDF时,我得到了:

  

" TCPDF错误:[图像]无法获得图像的大小:@"

并且无法生成PDF。

我的代码:

<?php 
tcpdf(); 
$obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 
$obj_pdf->SetCreator(PDF_CREATOR); 
$title = "PDF Report"; 
$obj_pdf->setPrintHeader(false); 
$obj_pdf->setPrintFooter(false); 

$obj_pdf->SetTitle($title); 
$obj_pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $title, PDF_HEADER_STRING); 
$obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); 
$obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); 
$obj_pdf->SetDefaultMonospacedFont('helvetica'); 
$obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER); 
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER); 
$obj_pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); 
$obj_pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); 
//$obj_pdf->SetImageScale(PDF_IMAGE_SCALE_RATIO); 



$obj_pdf->SetFont('helvetica', '', 9); 
$obj_pdf->setFontSubsetting(false); 
$obj_pdf->AddPage(); 

$obj_pdf->setJPEGQuality(75); 

// we can have any view part here like HTML, PHP etc 
$content = ob_get_contents(); 

ob_end_clean(); 
$obj_pdf->Image('@'.$content,'50'); 
//$obj_pdf->Image(); 
$obj_pdf->writeHTML($content, true, false, true, false, ''); 

$obj_pdf->Output('output.pdf', 'I'); 
?> 

此外,来自php端的allow_url = on

0 个答案:

没有答案