Active Sheet to PDF -- performance improvements and optim. for large sheets

Posted by: georgeg on 8 December 2025, 6:10 pm EST

    • Post Options:
    • Link

    Posted 8 December 2025, 6:10 pm EST

    Hi,

    I need some help improving the performance of big files to be converted to PDF… if possible.

    //This is the routine that will send the PDF attachment once 
    // the send or a button is pushed. Called by the button's click or
    // on click event handler (click is KendoButton handler).
    
    function sendActiveSheetAsPdf(fileName) {
      const recipientEmail  = $("#email-to").val();
      const optionalMessage = $("#email-message").val() || "";
      if (!recipientEmail) { alert("Please enter a recipient email."); return; }
    
      const designer = GC.Spread.Sheets.Designer.findControl(document.getElementById("designerHost"));
      const spread   = designer.getWorkbook();
      const sheet    = spread.getActiveSheet();
    
      // Tweak print settings on the active sheet (avoid expensive operations—see §2)
      const pi = sheet.printInfo();
      pi.bestFitColumns(false); // disable – expensive on large data
      pi.orientation(GC.Spread.Sheets.Print.PrintPageOrientation.landscape);
      pi.paperSize(GC.Spread.Sheets.Print.PaperKind.letter);
      pi.fitPagesWide(1);
      pi.fitPagesTall(0);
      sheet.printInfo(pi);
    
      // --- Build a lightweight workbook with only the active sheet ---
      const tempWb   = new GC.Spread.Sheets.Workbook();          // no host: off‑screen workbook
      const tempWs   = new GC.Spread.Sheets.Worksheet(sheet.name);
      // Copy the sheet via JSON to avoid cross‑links to the big workbook
      tempWs.fromJSON(sheet.toJSON());
      tempWb.addSheet(0, tempWs);
    
      // Export the temporary workbook to PDF
      tempWb.savePDF(
        function (blob) {
          const formData = new FormData();
          formData.append("file", blob, fileName);
          formData.append("recipientEmail", recipientEmail);
          formData.append("senderEmail", "joeClient@pipkins.com");
          formData.append("optionalMessage", optionalMessage);
    
          fetch("https://localhost:7049/MailKitExamplesTwo/sendPdfAttachment2", {
            method: "POST",
            body: formData
          })
          .then(r => {
            if (!r.ok) throw new Error(`HTTP ${r.status}`);
            console.log("PDF emailed successfully. STATUS:", r.status);
          })
          .catch(err => console.error("Error:", err));
    
          $("#email-pop-up-window").data("kendoWindow").close();
        },
        function (error) {
          console.error("PDF export error:", error);
          alert("Failed to export the sheet to PDF.");
        },
        {
          // No need for sheetIndex – tempWb has only one sheet
          title: "Active Sheet",
          author: "SpreadJS",
          subject: "Exported from Designer",
          keywords: "SpreadJS, PDF"
        }
      );
    

    This is fine for small sheets but when they get big…over 7400 rows and greater than 20 rows…oof! takes a while to send. Is there maybe a better way to handle the big files? The client really wants PDF. I was hoping for XLSX…but would that help maybe?

    Thanks!

    George

  • Posted 10 December 2025, 1:46 am EST

    Hi George,

    We reviewed the PDF export workflow and also benchmarked it against a dataset similar to yours (around 7,400 rows * 20 columns). The results were consistent with what you’re seeing:

    • XLSX export: completes in under 1 second
    • PDF export: takes roughly 18–22 seconds

    This difference is expected due to the way the two formats are generated.

    Excel (XLSX)

    XLSX is a structural format. SpreadJS can serialize the workbook directly without performing layout, pagination, or text measurement. The process is data-driven and fast, even with large sheets.

    PDF

    PDF generation is a rendering operation. Before creating the PDF, SpreadJS must:

    • measure and layout all cells
    • resolve styles, fonts, borders
    • compute row/column sizes
    • paginate the sheet
    • draw each page into a PDF canvas

    For large grids, these UI-driven calculations dominate the processing time. Even exporting through a temporary off-screen workbook does not reduce that cost, because the rendering workload is inherent to PDF output.

    Recommendation

    For large datasets, XLSX will always outperform PDF by a large margin. If the workflow allows it, exporting to Excel is the preferred option. PDF is feasible, but the processing time you’re seeing aligns with the expected rendering cost for sheets of this size.

    You can also refer to the attached sample application, which demonstrates PDF and Excel benchmarking using data of a similar size to your workflow (see below).

    Please let us know if you encounter any further issues or require any further assistance.

    Kind Regards,

    Chirag

    Sample: https://jscodemine.mescius.io/share/J3PIsPo5MEKIuLda3I1zNQ

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels