We are facing an export an excel file content to the PDF file, which is taking longer period in processing. what are the constraint need to considered for downloading a file of PDF from an excel file
Exporting Excel to PDF with Aspose.Cells for .NET – Performance Tips
Below is a quick checklist and a sample code snippet that will help you minimise the conversion time when saving an XLSX/XLS workbook as a PDF file.
Common factors that affect conversion speed
Factor | Why it matters | How to mitigate |
---|---|---|
Workbook size – number of worksheets, rows, columns | More cells → more data to render | • Remove unused worksheets. • Delete empty rows/columns ( Worksheet.Cells.DeleteBlankRows(); ). |
Formulas & calculation engine | Each formula is evaluated before rendering | • Set Workbook.Settings.CalcEngineEnabled = false; (if you do not need up‑to‑date results).• Or call Workbook.CalculateFormula() once and then disable further calculation. |
Charts, Images, Shapes | Each graphic is rasterised during PDF generation | • Delete unnecessary objects. • Reduce image resolution ( PdfSaveOptions.ImageResolution ). |
PageSetup (margins, scaling, fit‑to‑page) | Complex page settings require extra layout work | • Use simple page settings (Worksheet.PageSetup.FitToPagesWide = 1; etc.). |
Font handling | Embedding many fonts increases processing | • Use system fonts only, or set PdfSaveOptions.EmbedStandardFonts = true; . |
Memory‑optimisation mode | Large files may trigger full in‑memory rendering | • Enable PdfSaveOptions.OptimizeMemory = true; (streaming mode). |
Compression / Image quality | High‑quality images take longer to encode | • Choose a compression type (PdfCompressionType.Jpeg ) and set a lower ImageQuality if acceptable. |
Recommended PdfSaveOptions for faster conversion
using Aspose.Cells;
using Aspose.Cells.Rendering;
// Load the workbook (you can also use LoadOptions to skip calculation)
Workbook wb = new Workbook(@"C:\Input\largeFile.xlsx");
// OPTIONAL: If you do not need any formula recalculation
wb.Settings.CalcEngineEnabled = false; // disables automatic calculation
// Simplify page setup (example: fit all columns on one page)
foreach (var sheet in wb.Worksheets)
{
sheet.PageSetup.FitToPagesWide = 1;
sheet.PageSetup.FitToPagesTall = 0; // unlimited height
}
// Configure PDF save options for speed
PdfSaveOptions pdfOpts = new PdfSaveOptions
{
// Stream the output instead of loading everything in memory
OptimizeMemory = true,
// Reduce image resolution/quality if high fidelity is not required
ImageResolution = 96, // DPI (default is 150)
ImageQuality = 80, // 0‑100 (lower = faster)
// Choose a fast compression algorithm
Compression = PdfCompressionType.Jpeg,
// Embed only standard fonts (avoid embedding custom fonts)
EmbedStandardFonts = true,
// Disable writing of hidden worksheets (if any)
SaveHiddenSheets = false,
// Render only the first page for testing (remove for full export)
// PageCount = 1
};
wb.Save(@"C:\Output\result.pdf", SaveFormat.Pdf, pdfOpts);
Key points in the example
OptimizeMemory = true
forces Aspose.Cells to write the PDF page‑by‑page, greatly reducing RAM usage and often speeding up large conversions.- Lowering
ImageResolution
andImageQuality
cuts the time spent encoding raster graphics. - Disabling automatic calculation (
CalcEngineEnabled = false
) skips the formula engine entirely. - Simple
FitToPagesWide
page setup reduces layout complexity.
Additional Tips
Tip | How to apply |
---|---|
Use the latest Aspose.Cells version | Performance improvements are added in each release. |
Process only needed sheets | wb.RemoveWorksheet("SheetToIgnore"); before saving. |
Avoid repeated saves | Convert once per workbook rather than per sheet. |
Parallel processing (if you have many files) | Run conversions in separate threads/processes – each workbook conversion is thread‑safe. |
Profile the workbook | Call wb.CalculateFormula(); once, then measure the time spent on Save . This tells you if calculations dominate the runtime. |
Cache frequently used fonts | Load custom fonts once via FontConfig and reuse the same Workbook instance. |
Helpful Documentation Links
- Convert Excel to PDF – https://docs.aspose.com/cells/net/convert-excel-to-pdf/
- PdfSaveOptions reference – https://apireference.aspose.com/cells/net/aspose.cells/pdfsaveoptions
- Optimizing memory usage – https://docs.aspose.com/cells/net/optimize-memory-usage/
- Improving performance of large workbooks – https://docs.aspose.com/cells/net/performance-tips/
Next Steps
- Profile your current conversion (stop‑watch around
Workbook.Save
). - Apply the options above gradually to identify the biggest gain.
- If the workbook still takes too long, consider splitting it into smaller workbooks before converting.
Feel free to share a code snippet or a sample of the workbook (size, number of sheets, presence of charts/images) if you need more targeted advice. Happy converting!
@pavan-edu
Would you like to provide your sample files and runnable test code? Please compress files and code into zip format and upload them here. We will check it soon.
here is the block of code used for rendering the excel document to pdf,
ExpertPdf.HtmlToPdf.PdfDocument.Document pdfAttachment = null;
using (MemoryStream sourceStream = new MemoryStream(attachment.FileData.ToArray()))
{
Aspose.Cells.Workbook attachmentDocument = new Aspose.Cells.Workbook(sourceStream);
attachmentDocument.Save(targetStream, Aspose.Cells.SaveFormat.Pdf);
targetStream.Flush();
targetStream.Seek(0, SeekOrigin.Begin);
}
if (targetStream.Length > 0)
{
using (MemoryStream pdfStream = new MemoryStream(65536))
{
Aspose.Pdf.Facades.PdfFileStamp stamp = new Aspose.Pdf.Facades.PdfFileStamp(targetStream, pdfStream);
RectangleF renderRegion = document.Pages[0].ClientRectangle;
stamp.StartingNumber = document.Pages.Count + (!string.IsNullOrEmpty(sectionName) ? 2 : 1);
stamp.AddPageNumber(new Aspose.Pdf.Facades.FormattedText("Page #", Color.Black, Color.Transparent,
Aspose.Pdf.Facades.FontStyle.TimesRoman, Aspose.Pdf.Facades.EncodingType.Winansi, false, 9), 1,
40, 40, 40, 40);
stamp.AddPageNumber(new Aspose.Pdf.Facades.FormattedText(DateTime.Now.ToShortDateString(), Color.Black, Color.Transparent,
Aspose.Pdf.Facades.FontStyle.TimesRoman, Aspose.Pdf.Facades.EncodingType.Winansi, false, 9), 5,
40, 40, 40, 40);
stamp.Close();
pdfAttachment = new ExpertPdf.HtmlToPdf.PdfDocument.Document(pdfStream); //Creates a new pdf document with stream content.and appends to the orginal pdf document
}
}
if (pdfAttachment != null)
{
if (!string.IsNullOrEmpty(sectionName))
{
StringWriter writer = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);
htmlWriter.Write("<html xmlns='http://www.w3.org/1999/xhtml'>");
htmlWriter.Write("<head>");
htmlWriter.Write("</head>");
htmlWriter.Write(string.Format("<body style='{0}'>", DocumentBodyStyle));
RenderH2(htmlWriter, sectionName);
htmlWriter.Write("</body></html>");
htmlWriter.Flush();
pdfConverter.PdfFooterOptions.PageNumberingStartIndex = document.Pages.Count;
ExpertPdf.HtmlToPdf.PdfDocument.Document sectionDocument = pdfConverter.GetPdfDocumentObjectFromHtmlString(writer.ToString(), HttpContext.Current.Request.Url.AbsoluteUri); //if any section exists, //Creates a new pdf document with stream content.and appends to the orginal pdf document
document.AppendDocument(sectionDocument); //Appends the sectionDocument to the orginal pdf document
}
document.AppendDocument(pdfAttachment); //Appends the sectionDocument to the orginal pdf document
}
1mb.zip (1.1 MB)
@pavan-edu
By testing with the following sample code and files on the latest version v25.8, we were able to save the file to PDF normally, taking approximately 11 seconds. Due to the large amount of content in the file, the generated result file contains 164 pages of content. 11 seconds is an acceptable output result. Please refer to the attachment. out_net.pdf (8.7 MB)
DateTime time = DateTime.Now;
MemoryStream targetStream = new MemoryStream();
Aspose.Cells.Workbook attachmentDocument = new Aspose.Cells.Workbook(filePath + "1mb.xlsx");
attachmentDocument.Save(targetStream, Aspose.Cells.SaveFormat.Pdf);
targetStream.Flush();
targetStream.Seek(0, SeekOrigin.Begin);
//attachmentDocument.Save(filePath + "out_net.pdf");
Console.WriteLine(DateTime.Now.Subtract(time).ToString());
The output:
00:00:11.3519227
Also, how long did your entire processing take? If the overall time consumption is too high, please check if other processing steps have taken up too much time.
@John.He ,
Thank you for your response and appreciated.
In our requirement, we have form data with a N’number of fields in a form and including a file upload field and stores in the database on submit. While accessing the data from UI, we have given an option to the user to download the data along with the attached file content as appending it at the last. In this processing (excel to PDF) part is taking larger time.
I have share you the partial piece of code and with a sample content (1MB size). We are tried with multiple files with the sizes likely 10MB, 20MB, 35MB. For an instance, the 20MB file takes 8 to 9 mins of time to convert & download.
Of course, the processing time depends on the content file size, but which blocks the UI screen. So, Is there any way or alternate approach that can be increase the performance?
@pavan-edu
As the data increases, the conversion time from sample files to PDF will also increase accordingly. We have analyzed your example file and found that the data almost fills the area that needs to be exported. There is currently no better way. If you only need to export partial data of the file as a PDF, you can use the PdfSaveOptions.PageIndex and PdfSaveOptions.PageCount attributes. Please refer to the following example code and check the attachment. out_net.pdf (1.1 MB)
DateTime time = DateTime.Now;
MemoryStream targetStream = new MemoryStream();
Aspose.Cells.Workbook attachmentDocument = new Aspose.Cells.Workbook(filePath + "1mb.xlsx");
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.PageIndex = 5;
saveOptions.PageCount = 10;
attachmentDocument.Save(targetStream, saveOptions);
targetStream.Flush();
targetStream.Seek(0, SeekOrigin.Begin);
//attachmentDocument.Save(filePath + "out_net.pdf", saveOptions);
Console.WriteLine(DateTime.Now.Subtract(time).ToString());
@John.He ,
Are there any file size limitations when converting Excel content to PDF?
Does the file size affect the Excel-to-PDF conversion process?
Any reference, will helps us.
There is no restriction on file size; you can seamlessly convert large Excel files to PDF using Aspose.Cells for .NET. However, please note that performance issue might arise when working with extremely large and complex workbooks containing heavy content, formulas and other binary data. You may also consider setting ‘PdfSaveOptions.OptimizationType’ to ‘PdfOptimizationType.MinimumSize’ while saving to PDF may help reduce the PDF size and enhance optimization.
Thank you for the details
You are welcome. If you have any additional questions or comments, please do not hesitate to contact us again.