Convert a Workbook to PDF and get it as byte array

I would like to convert a work book to a PDF file and get it as a byte array.

Thanks in Advance

Suresh

Hi Suresh,

You can use Aspose.Cells to convert an Excel file to PDF directly. I’m moving this thread to the related forum so that my colleague from the concerned team would be able to help you out properly.

Regards,

Hi,

See the following sample code for your reference.

Workbook workbook = new Workbook(“E:\Book1.xlsx”);

MemoryStream ms = new MemoryStream();
workbook.Save(ms, SaveFormat.Pdf);
ms.Seek(0, SeekOrigin.Begin);
byte[] buffer = new byte[ms.Length];
buffer = ms.ToArray();
MessageBox.Show(ms.Length.ToString()); //It provides me the length. -OK
FileStream fs = new FileStream(“e:\test\mygeneratedPDF.pdf”, FileMode.Create);
fs.Write(buffer, 0, buffer.Length);
fs.Close();
ms.Close();




thank you.