Blank PDF page as result of tcPDF output

Topics: Developer Forum
Jan 11, 2013 at 1:17 PM

Hi All!

I have project based on PHPExcel and I haven't had any problems with it until now...
I need to export my results as .xls and .pdf as well, so I downloaded and copyd all the tcPDF files into this directory: "/var/www/scripts/PHPExcel/Shared/PDF"

My export.php file looks like this:

This is the inicialization part of the PDF writer:

$objPHPExcel = new PHPExcel();

$rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF;
$rendererLibrary = 'PDF';
$rendererLibraryPath = dirname(__FILE__).'/scripts/PHPExcel/Shared/'.$rendererLibrary;
if (!PHPExcel_Settings::setPdfRenderer(
		$rendererName,
		$rendererLibraryPath
	)) {
	die(
		'Please set the $rendererName and $rendererLibraryPath values' .
		PHP_EOL .
		' as appropriate for your directory structure'
	);
}
...

This is the export section at the end of the file:

if($_GET['format'] == 'xls'){

	header('Content-Type: application/vnd.ms-excel');
	header('Content-Disposition: attachment;filename="export.xls"');

	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
	$objWriter->save('php://output');
	exit;
}

if($_GET['format'] == 'pdf'){

	header('Content-Type: application/pdf');
	header('Content-Disposition: attachment;filename="export.pdf"');
	
	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF'); 
	$objPHPExcel->setActiveSheetIndex(0);
	$objWriter->writeAllSheets();
	$objWriter->save('php://output');
	exit;
}

The XLS export is working without any problems, but the PDF export result is always only a BLANK PAGE, nothing more. (the pdf file is valid, I can open it, but it only has 1 blank page)

I can't see any errors in the Apache log, so right now I really don't know what could be the problem...

Can someone help me out here?

Thanks!

Jan 11, 2013 at 2:20 PM
Edited Jan 11, 2013 at 2:22 PM

Changed to mPDF:

 

//$rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF;
$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
$rendererLibrary = 'MPDF';
$rendererLibraryPath = 'scripts/PHPExcel/Shared/'.$rendererLibrary;


but this time the exported pdf file isn't valid... Acrobat Reader says: "Acrobat Reader could not open 'export.pdf' because it is either not a supported file type or because the file has been damaged"

 

The file itself is 225KB.

I found a PHP Warning in the apache log:

PHP Warning:  Cannot modify header information - headers already sent by (output started at /var/www/scripts/PHPExcel/Shared/MPDF/mpdf.php:30875) in /var/www/scripts/PHPExcel/Shared/MPDF/mpdf.php on line 1727

Coordinator
Jan 13, 2013 at 12:06 PM

You'd get that error if mPDF encountered non-utf8 characters in the markup when it's expecting all utf-8; other than that I'm not overly familiar with the inner working of those libraries; but it does suggest that there is some content in the Excel file that might be non-utf8

Jan 13, 2013 at 12:16 PM
MarkBaker wrote:

You'd get that error if mPDF encountered non-utf8 characters in the markup when it's expecting all utf-8; other than that I'm not overly familiar with the inner working of those libraries; but it does suggest that there is some content in the Excel file that might be non-utf8

I will check my export's file encoding. The procedure is the following by the way: the export.pdp file opens a xls file (there are 4 different xls input files), calculates each row and fills them in and then exports it as xls or pdf. The xls version works great, but the pdf return only a blank page. I think I didn't use UTF-8 encoding, because the title of the result xls wasn't correct encoded (I'm unsing hungarian characters)... I really hope this will solve the issue.