Every sheet exported to PDF has 2 pages

Dec 8, 2011 at 6:16 AM
Edited Dec 8, 2011 at 7:40 AM

Every sheet i export in pdf create an additional blank and empty page .... anyone know why?

Even if i don't write values in cells that might be on a second page...


   $objPHPExcel->getActiveSheet()->setCellValue('A1','2 sheet');
   $objPHPExcel->getActiveSheet()->setCellValue('B2','2 sheet B2');

    $objWriter = new PHPExcel_Writer_PDF($objPHPExcel);


(edited) no matter how many pages has the document (2-3-4 ....) exporter adds one more blank page to every sheet...

(ex: if i have 2 sheets...first with 2 pages of data and second with one page of data i will have a 5 page PDF )

Dec 9, 2011 at 5:58 AM

Seems like everyone has just renounced at the PDF functions of PHPExcel. All you guyz work with mPDF?

Dec 9, 2011 at 1:40 PM

Even I would renounce tcPDF if I could. mPDF is far better, and domPDF is also improving too... but the mPDF license means we can't switch to that without restricting the PHPExcel license as well, and domPDF isn't quite mature enough yet. I'm looking at a compromise where we allow you to specify which of the three libraries you want to use (but you'd need to install tcPDF, mPDF or domPDF yourself), and then remove the embedded PDF library completely from the PHPExcel distribution.

Dec 12, 2011 at 6:03 AM
Edited Dec 12, 2011 at 7:10 AM

Thanks :)....i'll have to go with mPDF considering that you guyz all recomended that. (including you Mark :) ).

So....exporting to html and then using mPDF right.

Could someone provide a few lines crashcourse if possible? Thanks :).

Pretty please? ;;)

Dec 12, 2011 at 4:07 PM

Here is a basic HTML to mPDF...


$mpdf = new mPDF('c', 'Letter-L');



Dec 13, 2011 at 1:53 PM

That i can get from every website i find searching google for mPDF...

i meant how to interrelate the PHPExcel obj with the mPDF library...

output the HTML writer and then use it with WriteHTML? Or i have to manually form the html to be passed to mPDF? (separately from the already existant excel "template")

P.S. It's plausible that i get on this discussion at heightened levels of tiredness and my comprehension levels drop to those of a 2'year old...so if that's the case excuse me :)

Dec 15, 2011 at 8:19 PM

I do it manually to fine-tune, but you can pass HTML made by PHPExcel right to it.

May 21, 2012 at 9:56 AM

Sorry for pushing this, but i have the exact same problem generating PDF from XLS.For every Page i generate, there is a blank one too.

The Problem has nothing to do with my specific code because it happens actually with the demo scripts of phpexcel too.

PHP: 5.3.9 - Zend Server 5.6.0

Apache/2.2.20 (Ubuntu)

I understand, that putting out HTML and then converting it to PDF with another library solves the Problem, but I kind of expect this to work out of the box ;)

Any ideas? Thanks!

Jun 21, 2012 at 5:12 PM

I solved this problem for my self by changing the line in the PDF save function.

Its in the Classes/PHPExcel/Writer/PDF.php file line 283. version 1.7.6, 2011-02-27


$pdf->SetAutoPageBreak(true,$printMargins->getBottom() * 72);


$pdf->SetAutoPageBreak(false,$printMargins->getBottom() * 72);

Jun 21, 2012 at 10:39 PM

This should not be an issue in the latest develop branch code on github