Excel5 to PDF generates empty file

Topics: Developer Forum, User Forum
Jan 19, 2009 at 5:00 AM
I want to load an XLS template, manipulate the content, and save the result as PDF file.

The problem is :
It does produce a PDF file, but the file size is 0 bytes and unreadable.

This is the code :
<?php

require_once('PHPExcel.php');
require_once('PHPExcel/IOFactory.php');

$template_location = 'template.xls';

// Load XLS template
$xls_reader = PHPExcel_IOFactory::createReader('Excel5');
$excel = $xls_reader->load($template_location); // Loaded successfully, var_dump outputs correctly

// Save as PDF
$xls_writer = PHPExcel_IOFactory::createWriter($excel, 'PDF');
$xls_writer->save('result/from-template.pdf');

In this case, 'template.xls' is a fresh blank spreadsheet created from openoffice calc.
When i try createWriter(new PHPExcel(), 'PDF'), it outputs the PDF file correctly, with no problem.

Is this a bug ?
Developer
Jan 19, 2009 at 1:55 PM
This is strange... I cannot reproduce the problem. With your script, I get a PDF file 8KB using blank template.xls created in OpenOffice.org 3

Jan 19, 2009 at 3:21 PM
I wonder what the problem is :-(

But never mind, i finally decided to output excel file instead of PDF (this is the best solution in my case).
I put non-CI code in my CI application to do the tasks.

And then i ran into another problem (argh . .)

Koyama,
Sorry a bit off topic. I have an XLS file that can be read, but cannot be written into any format (i tried Excel5, Excel2007, PDF).
Would you see the file for me and find out what's wrong here ? I'll email it to you if you would like to. Thanks for your concern :p . .
Developer
Jan 19, 2009 at 7:01 PM
I will take a look at the xls file. Please send it to (erik at phpexcel dot net)

Feb 13, 2010 at 5:59 PM

I've searched the discussion forums and this topic seems the closest to what my problem is (based on situation described).

[ang89] is using the createReader to open the file and write it right back as a PDF, which is (nearly) identical to what I am doing (as a test), but with an .xlsx file.

I'm not sure, but I think it's from the overhead of loading the file? The {01simple-download-pdf.php} and {21pdf.php} test files work just fine, but they are starting with a New file, not loading an existing one.

[koyama]: Would you like the sample xlsx file I am using?

Developer
Feb 17, 2010 at 12:17 AM
crmoffice wrote:

I've searched the discussion forums and this topic seems the closest to what my problem is (based on situation described).

[ang89] is using the createReader to open the file and write it right back as a PDF, which is (nearly) identical to what I am doing (as a test), but with an .xlsx file.

I'm not sure, but I think it's from the overhead of loading the file? The {01simple-download-pdf.php} and {21pdf.php} test files work just fine, but they are starting with a New file, not loading an existing one.

[koyama]: Would you like the sample xlsx file I am using?

Yes, please upload the file here and I will take a look:

http://phpexcel.codeplex.com/WorkItem/View.aspx?WorkItemId=10749

Feb 17, 2010 at 7:20 PM

ThreadID=44529&Filename=New_FNF.xlsx Uploaded Successfully.

A new oddity that cropped up into this file is that the first (and only) tab is duplicated sometime during the process before the data insertion begins, I'm not entirely sure what could cause that as I am not using any commands that relate to that function.

Developer
Feb 18, 2010 at 11:19 PM

@crmoffice: I can confirm that the script goes into what seems like an infinite loop when one exports your xlsx file to PDF.

I think this is an infinite loop bug in TCPDF occurring under special circumstances when there are colspans and the table is wider than the page width.

https://sourceforge.net/tracker/?func=detail&aid=2886239&group_id=128076&atid=710532

You may try to use a larger paper size such as A3.