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
