Convert Worksheet to PDF

Hi,

I am trying to convert excel output to pdf. The content is generated programmatically and then I am trying to get the output as pdf. I am using the below code. (NOTE: excel is Worksheet object. )

excel.Save(outputStream, Aspose.Cells.FileFormatType.AsposePdf)

Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()

pdf.BindXML(outputStream, Nothing)

pdf.Save(outputStream)

excel = Nothing

outputStream.Seek(0, SeekOrigin.Begin)

Response.AddHeader("Content-Disposition", "attachment; filename=report.PDF")

Response.ContentType = "application/pdf"

outputStream.Close()

Response.End()

The promt to open PDF file is coming, but when I click on Open I get the error message: "Adobe Reader could not open 'report.PDF' because it is either not a supported file type or because the file has been damaged."

Can anyone help. Thanks in advance.

Hi,

Thanks for the post. Can you please try the attached version of Aspose.Cells for .NET? Also please give a try to the following code after creating the Workbook through the attached version:

     'Save Xls File to PDF
book.Save(“Xls2Pdf.pdf”, FileFormatType.Pdf, SaveType.OpenInExcel, System.Web.HttpContext.Current.Response)

'End response to avoid unneeded html after xls
HttpContext.Current.Response.End()
Where book is Workbook object. If the problem persists, please provide a sample project exhibiting the problem so that we can reproduce the issue.

Best Regards

Hi,

Thanks for the above reply.

I tried as you said but unfortunately, it is not working. I am getting the same error again.

Also, as I said above in the told, is it possible to use System.IO.Filestream (outpuStream) object instead of saving as Xls2Pdf.pdf

Thank you.

Hi,

Yes, it should work as well.

Can you please provide some sample project in order to investigate the issue you are facing?

Best Regards

Hi,

With the below code it is working.

excel.Save("Xls2Pdf.pdf", FileFormatType.Pdf, SaveType.OpenInExcel, System.Web.HttpContext.Current.Response)

As said in earlier threads I was creating Aspose.pdf.pdf object. Now I removed the code to create Aspose.pdf.pdf object and it is working now.

Thank you.