We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Workbook to PDF

I have a workbook where I dynamically add worksheets, but I need to have it downloadable as a PDF file. If I save the work book to the response with PDF format, everything works correctly. However, the end goal is to send the PDF as an email attachment. I have tried saving the workbook to a stream in multiple ways, and then either writing the stream to the response or creating an attachment object and sending the email. Is there a way to accomplish my goal of performing all of the work in an aspose workbook and then sending the file as a PDF email attachment?

I'm using C#.NET. I have ASPOSE.CELLS 4.8.1.

In order to create the stream, I tried these two methods

MemoryStream stream = new MemoryStream();

bookDesinger.Workbook.Save(stream, FileFormatType.Pdf);


MemoryStream stream = bookDesinger.Workbook.SaveToStream();

This message was posted using Aspose.Live 2 Forum


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Please check the sample code below to convert an Excel file to PDF and send as an email attachment.

Aspose.Cells.Workbook Excel = new Workbook();

Worksheets Sheet = Excel.Worksheets;

MemoryStream ms = null;

ms = new MemoryStream();

Excel.Save(ms, FileFormatType.Pdf);

MailMessage mail = new MailMessage();

mail.To.Add(new MailAddress(ToEmail);

mail.From = new MailAddress(FromEmail);

mail.Subject = "Test";

mail.Body = "Test";

mail.IsBodyHtml = true;

if (ms != null)


ms.Seek(0, SeekOrigin.Begin);

mail.Attachments.Add(new Attachment(ms, "new", "application/pdf"));


SmtpClient smtp = new SmtpClient();

smtp.Port = Port;

smtp.Host = Host;



Thank You & Best Regards,

Is it also possible to shrink the contents to fit a single PDF page? Similar to the “shrink to fit” ioption when printing.


I think you may use: PdfOptions.OnePagePerSheet = True
before saving to PDF file for your need.

Dim wb As Aspose.Cells.Workbook = New Aspose.Cells.Workbook
PdfOptions.OnePagePerSheet = True
wb.Save(outpath, FileFormatType.Pdf)

Thank you.