Saving to PDF: first Save() fails (old subject: unsupported sfnt version)

I’m trying to convert a simple Excel document to PDF and receive the following error when I call the Save() method: "Unsupported sfnt version."

The code:

var doc = new Aspose.Cells.Workbook();
doc.Open(sourceFilePath);
doc.Save(destinationPath + “\” + sourceFileNameNoExt + “.pdf”, Aspose.Cells.FileFormatType.Pdf);

Any ideas what might be causing this?

Hi,

Could you post your template excel file here, we will check you issue soon.

Thank you.

Attached please find the .xls document that is giving me issues. I forgot to add that, despite the exception being thrown, a PDF file is created. However, it is blank and Acrobat Reader reports it as corrupted after opening.

Hi,

Thank you for sharing your template file.

I have tested your file with the latest version of Aspose.Cells (attached) and it works fine. Please try the attached latest version.

Thank You & Best Regards,

Hi,

And, after further analyzing your issue, we found that your file might have some problems regarding font. For example, when the file is opened with excel 2003 , the font name can be seen, but when the file is opened with excel 2007, the font name can't be seen. Is it so? We also want to know how did you create the template file, do you use open office?.

Thanks for providing us further details, so that we can dig into your issue further.

Thank you.

Hi,

Thank you for considering Aspose.

Please try the attached latest fix of Aspose.Cells. We have fixed your mentioned issue regarding XLS2PDF conversion…

Thank You & Best Regards,

I am still having issues. An error is no longer thrown during conversion, however, the resulting PDF file is still 0kb and Acrobat Reader still reports the file as corrupted when trying to open. Additionally, when trying to delete the PDF after conversion, Windows reports that it is still in use and cannot be deleted (I must kill my process). However, I am able to delete successfully converted files immediately after conversion, even while my process is still running.

I have attached the Excel file I am testing with again. It was created in Office 2007 and saved as .xls; nothing else was done to the file. I have had no trouble with conversion when I save the same file as .xlsx (also attached).

  • Conversion fail.xls - fails
  • Conversion success.xlsx - works
Any help would be greatly appreciated.

Hi,

Thank you for considering Aspose.

Well, I have tested you provided file "Conversion fail.xls" and I am able to convert the file successfully using Aspose.Cells V4.7.0.3 (attached in my last post). Also, I have attached the generated PDF file. Please create a sample test application and post it here and we will check it soon. Also, please provide some further details about your environment like version of Visual Studio, IIS and Windows etc you are using.

Thank You & Best Regards,

Hi,

Thank you for considering Aspose.

Please try the attached latest version of Aspose.Cells. We have done some further modifications in the XLS2PDF conversion process. Please let us know if it works fine as per your requirement.

Thank You & Best Regards,

Thank you for the continued support. I am still encountering the issue with v4.7.0.4. I have developed a workaround and have attached the code I am using.

Basically, I dump any number of random .xls/.xlsx files into the target directory and run the console app. Conversion will always fail for the first Excel file on the first call to the Save() method (it results in a 0KB .pdf file). If I then call the Save() method again immediately, the conversion works just fine.

Hopefully this helps narrow down the issue.

Hi,

Thank you for providing the sample application, We will look into it and get back to you soon.

Thank You & Best Regards,

Hi,

Thank you for considering Aspose.

We have created a Debug version of Aspose.Cells V4…7.0.4 to gather more information regarding your issue. Please download it and provide us with the complete error information as per you problem. This will help us in figuring out the issue quicker.

Please grant the “write to disk authorization” to the test project, then run it and send us AsposeCells.log and AsposeCells_2.log from “c:”.

Also, please try saving pdf to MemoryStream then saving the MemoryStream to file. Use this way to clarify which step has problem.

Thank you for your understanding and support,

I have been running into this issue as well. Has any work around/fix been found?


It is just the first file, it seems like it doesn’t matter what the excel file is, just that it is the first on opened in the loop.

Saving to memory streams and then saving to PDF doesn’t seem to help.

Thanks,

John

John,

I’m using the following method as a workaround (C#) and it’s been successful. Simply save the file a second time if the initial PDF’s size is 0…

var doc = new Aspose.Cells.Workbook();
doc.Open(sourceFilePath);
doc.Save(destFile, Aspose.Cells.FileFormatType.Pdf);

// Here we have the workaround.
if (new FileInfo(destFile).Length == 0)
doc.Save(destFile, Aspose.Cells.FileFormatType.Pdf);

Hi,

Thank you for considering Aspose.

We have created a Debug version of Aspose.Cells to gather more information regarding your issue. Please download it and provide us with the complete error information as per you problem. This will help us in figuring out the issue quicker.

Please grant the “write to disk authorization” to the test project, then run it and send us AsposeCells.log and AsposeCells_2.log from “c:”.

Also, please try saving pdf to MemoryStream then saving the MemoryStream to file. Use this way to clarify which step has problem.

Also, please provide some further details about environment like version of Visual Studio, IIS , Windows, language of windows, and which type of machine (x86|amd, 32|64) you are using.

Thank you for your understanding and support,

I have not yet purchased your product, but I am using your demo version Aspose.Cells. I was getting the same error above, then I downloaded the fix you attached to this case. I am now not getting the error, but the PDF file is not viewable. Any ideas? I would like to know ASAP because I have some other products like yours I am looking at.

Hi,

Thank you for considering Aspose.

Please share your template excel file with us and we will check your issue soon. Also, please try our latest version of Aspose.Cells and check if it works fine for your. You can download the latest version from the following link,

Thank You & Best Regards,

I have your same problem.
Try this:

try
{
doc.Save(destinationPath + “\” + sourceFileNameNoExt + “.pdf”, FileFormatType.PdF);
}
catch(Exception ex)
{
Save();
}

Hi,

Which version of the component you are using? please try our latest version v4.7.1.x.

If you still find the issue, create a sample console application (with your template file(s)) to show the issue, we will check it soon.

Thank you.

Hi,

I have the same problem, and I am using version 4.7.1.0 of Cells. and VB .net - Visual studio 2008.

On my development machine everything works, but not on any machine I deploy to.

Any ideas other than the try catch method mentioned above?

Steve