0

I can read an xlsx file using PHPSpreadsheet just fine. The problem is that when I try to write it out to PDF the result is blank when I bring it up in Acrobat, even though the PDF file is about 840K.

I have tried Mpdf and Dompdf but they either take too long and time out, or run out of memory.

The .xlsx file is only 161K.

Here is the gist of my code:

$full_file_path = "/full/path/to/my/file.xlsx";
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile($full_file_path);
$excelSpreadsheet = $reader->load($full_file_path);

$PDFWriter = new \PhpOffice\PhpSpreadsheet\Writer\Pdf\Tcpdf($excelSpreadsheet);

$PDFWriter->writeAllSheets();

$PDFWriter->save("blarg.pdf");

When I run this code blarg.pdf gets updated and has a size of around 843K. But, when I open it in Acrobat it shows up as blank.

No errors appear in the logs.

In a separate test I was able to write out the Excel file as (ugly) HTML just fine.

Any idea what I'm doing wrong?

Random facts:

  • Excel file has multiple sheets.
  • Excel file created by Excel for Mac version 15.28
  • Mac OSX Sierra 10.12.6
  • PHP 5.6.28
  • phpoffice/phpspreadsheet : 1.1.0
  • tecnick.com/tcpdf : 6.2.13
David Ranney
  • 59
  • 2
  • 11
  • does an excel file with only on cell with one word work? have you opened the pdf in a text editor, check the top and bottom for php errors? –  Feb 06 '18 at 22:13
  • I created a very simple .xlsx file with two sheets with two columns and two rows, and that worked just fine. The top of the blank PDF starts with %PDF-1.7 and the bottom of the PDF ends with %%EOF I didn't see any PHP errors – David Ranney Feb 06 '18 at 22:43
  • sounds like its an issue with some specific content, i would slow add content to the xls until you find what the actual issue –  Feb 06 '18 at 22:59
  • As a test I manipulated the original .xlsx file to remove all but one sheet, all formatting, and all formulas. I got it down to a sheet of columns A-N and rows 1-69. All text and numbers. With Tcpdf it did finally produce a PDF, but the PDF was incomplete, cutting off around row 21. It did get all the rows. I'm going to try some experimentation with Mpdf and Dompdf again. – David Ranney Feb 07 '18 at 19:28

0 Answers0