We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Improve memory & performance while print & export the Spreadsheet?

Platform: WPF |
Control: SfSpreadsheet

We can improve the performance and memory consumption while exporting to PDF document, the cell “G4” is calculated which contains another calculated formula that depends on another calculated formula and so on. Due to these recursive operations, stack value throws an exception while exporting the document to PDF.

This problem can be resolved in sample level by setting the maximum size of stack while exporting the workbook with new thread.


private static void OnExecuteDirectPrint(object sender, ExecutedRoutedEventArgs args)
    spreadsheetControl = args.Source as SfSpreadsheet;
    //Create the pdfviewer for load the document.   
    PdfViewerControl pdfviewer = new PdfViewerControl();
    // PdfDocumentViewer   
    pdfstream = new MemoryStream();
    var maxSize = 10000000;
    var thread = new Thread(PrintFromPdfViewer, maxSize);
    //Load the document to pdfviewer   
    //Show the print dialog.   


You must set the AllowShortCircuitIFs and MaximumRecursiveCalls properties in threading while printing or exporting to PDF.


private static void PrintFromPdfViewer()



    spreadsheetControl.ActiveSheet.Workbook.Worksheets[0].CalcEngine.AllowShortCircuitIFs = true;

    spreadsheetControl.ActiveSheet.Workbook.Worksheets[0].CalcEngine.MaximumRecursiveCalls = 10000;


    ExcelToPdfConverter converter = new ExcelToPdfConverter(spreadsheetControl.Workbook);

    //Intialize the PdfDocument  

    PdfDocument pdfDoc = new PdfDocument();


    //Intialize the ExcelToPdfConverter Settings  

    ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();

    settings.LayoutOptions = LayoutOptions.NoScaling;


    //Assign the PdfDocument to the templateDocument property of ExcelToPdfConverterSettings  

    settings.TemplateDocument = pdfDoc;

    settings.DisplayGridLines = GridLinesDisplayStyle.Invisible;


    //Convert Excel Document into PDF document  

    pdfDoc = converter.Convert(settings);


    //Save the PDF file  




Sample Link - WPF


2X faster development

The ultimate WPF UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile