Hi everybody,
I'm quite new with spire xls. I'm trying to convert an excel workbook to a pdf file that send back to the client via the Response.
After downloading the file, I cannot open it neither with GoogleChrome or adobe acrobat reader but with the pdf viewer from Mozilla it works just fine.
Adobe and googleChrome say that the file is damaged/corrupted.
Below is my code :
using (MemoryStream memoryStream = new MemoryStream(pck.GetAsByteArray()))
{
Workbook workbook = new Workbook();
workbook.LoadFromStream(memoryStream);
// Set PDF template
Spire.Pdf.PdfDocument pdfDocument = new Spire.Pdf.PdfDocument();
//Convert Excel to PDF using the template above
PdfConverterSettings settings = new PdfConverterSettings();
settings.FitSheetToOnePage = FitToPageType.ScaleWithSameFactor;
pdfDocument = PdfConvertionHelper.SaveToPdf(workbook, settings);
// Save and preview PDF
using (MemoryStream savePDFStream = new MemoryStream())
{
pdfDocument.SaveToStream(savePDFStream);
Response.ContentType = "pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + pdfFileName);
Response.OutputStream.Write(savePDFStream.GetBuffer(), 0, savePDFStream.GetBuffer().Length);
}
}
pck being an ExcelPackage object generated before
Thanks for your help