Test Simple PDF Blank Page

Topics: User Forum
Jan 20, 2011 at 3:58 PM

Is Tests/01simple-download-pdf.php expected to produce a blank page 2, in addition to the expected data on page 1?

I have PHPExcel 1.7.5, PHP 5.2.10, and CentOS 5.5.

Coordinator
Jan 30, 2011 at 1:16 PM

Perhaps not the best answer to give, but "probably".

PHPExcel uses a third-party library to actually build the PDF. What we do is build an HTML string (using the same basic output as the HTML Writer), and then feed that string to the tcPDF library that is bundled with PHPExcel.

tcPDF has a few problems... particularly with rendering cell borders correctly. It is also incredibly slow to build the PDF from HTML, and can't handle larger worksheets without using very large amounts of memory. I've been looking at a few alternatives, such as DomPDF and mPDF to perform the same function, but each has its pros and cons.

tcPDF

  • Pros
    No observed problems with any UTF-8 characters
    Supports Document Information properties
  • Cons
    Problems with borders, especially with merged cells
    Displays thick grid around non-null cells when setShowGridLines(true)
    Displays incredibly thick grid around all cells when setShowGridLines(false)
    Superscript/Subscript appear out of place wrt the cell borders
    Slow
  • Typical Performance
    Call time to save Worksheet 1 to PDF file was 23.6305 seconds
    Memory usage: 29.25 MB
  • Output file size is 894 KB


DomPDF

  • Pros
    Handles borders cleanly, even for merged cells
    Displays Superscript/Subscript correctly
  • Cons
    Misses the first row to be displayed on each page
    Requires PHP v5.2.9, otherwise it doesn't page correctly, but latest beta overwrites the first page with all subsequent pages
    Latest fixes (post) generates an addition blank page on every page break
    Can't display some UTF-8 characters
    Top Margin settings on 2nd and subsequent pages are ignored (suspect problem will be replicated with bottom margins on all but the last page)
    Displays grid only around null cells when setShowGridLines(true)
    No support for Document Information properties
  • Typical Performance
    Call time to save Worksheet 1 to PDF file was 16.6204 seconds
    Memory usage: 42.25 MB
  • Output file size is 13 KB


mPDF

  • Pros
    Handles borders cleanly, even for merged cells
    Correctly displays grid around all cells when setShowGridLines(true); no problems when setShowGridLines(false)
    No problems with any UTF-8 characters
    Supports Document Information properties
  • Cons
    GPLv2
    Memory-hungry
    Problems with subscripted text (can't see it in resultant PDF)
  • Typical Performance
    Call time to save Worksheet 1 to PDF file was 14.3668 seconds
    Memory usage: 69.25 MB
  • Output file size is 74 KB

None of the three works well with large worksheets.

mPDF is the best overall, fast and with very clean output (I might even be able to improve on the high memory usage): apart from the license issues, which conflicts with PHPExcel's LGPL license. I may have a word with the developers and see if they're willing to allow us to include it in our distribution under LGPL, but I'm not sure they would.

An alternative is for me to drop the actual PDF library itself from the distribution; and just provide wrappers for a number of the more popular libraries, so that you could use your own preferred PDF library, selecting it via PHPExcel_Settings before using the PDF Writer. One major benefit of this would be a drop in the size of the distribution. The PHPExcel classes directory and subdirectories take up about 19.6MB on disk, of which 16.8MB is tcPDF. (DomPDF needs 9.14MB and mPDF needs a mammoth 29.9MB).

If anybody is aware of any other PDF libraries that can render from HTML input, I'd be interested to know so that it could run comparative tests to see if there is anything better suited for rendering worksheets.

Feb 14, 2011 at 10:55 AM

Hello.  I have only been using PHPExcel for a short time, and I am really impressed with its capabilities.  I have been looking for the right combination of excel to pdf for quite some time.  I have been using Livedocx, but always have problems with it and it is limiting on its capabilities. 

Well to get to your poll.  To me I would think it would be better suited for your time to be spent on your package.  I think Developers like options and tying a single PDF package to PHPExcel may limit what a developer can do.  I have just recently been trying out mPDF and am so far happy with the output I have been seeing.  Your Excel template to HTML conversion is superb and makes it extremely easy to integrate both packages. This seems to work for me, but other PDF packages may offer features that other developers want over mPDF.  

To me, it seems that this would be the preferred route, but that is just my opinion. 

Feb 21, 2011 at 1:21 PM

I would like to choose as well, like some Drupal modules allow.

Can I use mPDF w/1.7.5?

Coordinator
Feb 21, 2011 at 1:51 PM
ScottMSanders wrote:

I would like to choose as well, like some Drupal modules allow.

Can I use mPDF w/1.7.5?


Not with version 1.7.5, unless you write your own PHPExcel_Writer_PDF.php to work with mPDF.

I have partially completed writing configurable wrappers for mPDF and DomPDF, and part-converted the existing tcPDF wrapper to be configurable; but haven't yet completed the configuration side of this. This feature is likely to be included in version 1.7.7 - targetted for around Easter, after the 1.7.6 release ( hopefully later this week ). I'd still like to bundle a default PDF library, so that the PDF option is still available "out of the box"; and to dump the existing bundled tcPDF. mPDF is (in my opinion) the best choice, but unfortunately the licenses do clash.

May 11, 2011 at 5:06 PM

Hi guys,
first thanks for such a perfect skript.

Here is the "quick solution" , if you see blank page after your PDF content generated.

Go to PHPExcel>Writer>PDF.php line 287 and insert just above $pdf->writeHTML($html) :

$html = "<html><head></head><body>".$html;
$html = str_replace("page-break-after:always","", $html);

 

I spent dose of time ... and I hope it will save yours :)

I guess in next version PHPExcel MarkBaker will update it

Sep 2, 2011 at 9:37 AM

Hi guys,

I'm also having the same issue with a blank page and the end of my PDF.

I tried jakubrulec solution but it didn't work.

I'm using PHPExcel 1.7.6

Did someone find a way to solve this ?

Thanks

Sep 2, 2011 at 12:16 PM

My solution: create HTML, and send to mPDF.

Sep 6, 2011 at 7:45 AM

Hi all,

I found a way to fix it, I downloaded the last version of TCPDF and added it in PHPExcel->Shared->PDF

I modified the script in PHPExcel->Writer->HTML.php and i commented the line 606 $css['table']['page-break-after'] = 'always';

Hope it will helps

Sep 21, 2011 at 9:54 AM

Can anyone place a little how-to implement the mPDF solution?

Sep 21, 2011 at 12:24 PM
Edited Sep 21, 2011 at 12:25 PM

There are some examples in the mPDF package that are fairly self-explanatory: http://www.mpdf1.com/mpdf/

You just need to provide your HTML which mPDF will make into a PDF.

Coordinator
Jun 4, 2012 at 9:40 PM

Latest SVN code for PHPExcel now allows choice of PDF Rendering library from tcPDF, mPDF and DomPDF.

Basic testing done using 05featuredemo.inc.php worksheet with the following versions:

  • tcPDF 5.9
  • mPDF 5.4
  • DomPDF 0.6.0beta3

Has not yet been tested with complex workbooks, or complex formatting

Problem with spurious blank last page has also been eliminated