1

I am using TCPDF for generating PDF from HTML. I have both content + graph in my page. I am able to download the content but not able to get the graphs image in PDF. I use google charts. It's not saving as image so I converted to PNG. Now my graph is loading as PNG, but when I try to download the PDF I am getting:

"TCPDF ERROR: [Image] Unable to get the size of the image: @"

and not able to generate PDF.

My code:

<?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'); 
?> 

Also, allow_url = on from php side.

Ravan Scafi
  • 6,382
  • 2
  • 24
  • 32
user3454272
  • 51
  • 1
  • 6
  • PLEASE CHECK THESE TWOLINKS:- http://stackoverflow.com/questions/7665540/tcpdf-error-image-unable-to-get-image. http://stackoverflow.com/questions/27060947/tcpdf-error-unable-to-get-the-size-of-the-image – Alive to die - Anant Apr 10 '15 at 12:03
  • I already saw this.It doesn't help – user3454272 Apr 10 '15 at 12:05
  • Are u using highcharts for graph? I have solution with that – Anand G Apr 10 '15 at 12:40
  • could you var_dump($content) and share the result? I am of the opinion that this line $obj_pdf->Image('@'.$content,'50'); cannot work the way you are trying. comment that out and what do you get? – Jonny C Apr 10 '15 at 12:42
  • I use google chart. @Jon C - even if I comment $obj_pdf->Image('@'.$content,'50'); its not at all working – user3454272 Apr 11 '15 at 04:04
  • When viewed in a browser the javascript from google charts generates the image, when you pass the html to tcpdf all it is getting is a string not an image so TCPDF wont be able to display the chart. it might be possible by doing something like this thread mentions, [http://stackoverflow.com/questions/24115215/php-tcpdf-image-string-filter](http://stackoverflow.com/questions/24115215/php-tcpdf-image-string-filter) – Jonny C Apr 11 '15 at 06:11

0 Answers0