Free Support Forum - aspose.com

Throw error: Invalid image file type aftering saving it as xls then trying to convert to PDF

Hi,

I am trying to convert a xls file to PDF but got this error: "Invalid image file type".

Can you please show me how to get this to work?

Thank you very much in advance. Below is my code:

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Name = "show currency";

string fileName = "logo.gif";
sheet.Pictures.Add(0,0, Server.MapPath(@"~\images\" + fileName));
sheet.Cells.ImportDataTable(dtData, true, "A8");

sheet.AutoFitColumns();

// Saving an XLS file in Aspose.Pdf xml format
workbook.Save("C:\\xlsToPDF.xls");
workbook.Open("C:\\xlsToPDF.xls");
workbook.Save("C:\\xls2pdf.xml", FileFormatType.AsposePdf);

// Converting XLS file to PDF through Aspose.Pdf using Aspose.Pdf xml file as a medium
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML("c:\\xls2pdf.xml", null);
pdf.Save("C:\\xls2pdf.pdf", Aspose.Pdf.SaveType.OpenInBrowser, this.Response);


saving it straight to xls works fine using the codes below:


String SaveAsFileName = "ShowCurrency"
_SaveAsFileName = SaveAsFileName + ".xls";
workbook.Save(_SaveAsFileName, FileFormatType.Default, Aspose.Cells.SaveType.OpenInBrowser, this.Response);

Hi,

Thanks for considering Aspose.

Could you post your image file or xls file here, we will check your issue soon.

By the way, which version of Aspose.Cells and Aspose.Pdf you are using.

Thank you.

I switched to use a differenct image to keep my client's data confidential. Converting to PDF also errored using the process.gif. I also attached the xlsToPDF.xls for your review.

Thanks for your help.

Sorry for not including the version info. in previous post. Here they are:

Aspose.PDF 3.3.2.0

Aspose.Cells 4.1.2.0

Hi,

Thanks for providing the template files.

Since you are using some older versions of the products. I tried the conversion (xls2pdf) using your template excel file, it works and the output pdf file is fine . I utilized the following latest versions / hot fixes of the products:

Aspose.Cells for .NET 4.5.0.12 (attached).

Aspose.Pdf for .NET 3.6.2.5

So, kindly try the attached version.

Thank you.