Posted 4 December 2025, 2:31 pm EST
Hi,
Encountered some issues when trying to tink with the format of the activeSheet as PDF I will eventually package for
email to my .NET Core Minimal API.
Here is my test code:
function sendActiveSheetAsPdf() {
const recipientEmail = $("#email-to").val();
const optionalMessage = $("#email-message").val(); // note the # to select by id
if (!recipientEmail) {
alert("Please enter a recipient email.");
return;
}
// Find Designer and get SpreadJS workbook
const designer = GC.Spread.Sheets.Designer.findControl(document.getElementById("designerHost"));
const spread = designer.getWorkbook();
const activeIndex = spread.getActiveSheetIndex(); // we need the index for savePDF
// (Optional) tweak print settings for better PDF layout on the active sheet
const sheet = spread.getActiveSheet();
const pi = sheet.printInfo();
pi.orientation(GC.Spread.Sheets.Print.PrintOrientation.landscape); // or portrait
pi.paperSize(new GC.Spread.Sheets.Print.PaperSize("letter")); // A4, Letter, etc.
pi.fitPagesWide(1); // fit to 1 page wide
pi.fitPagesTall(0); // unlimited height
sheet.printInfo(pi);
// Export active sheet to PDF. Aledgedly this will work.
spread.savePDF(
function (blob) {
const formData = new FormData();
formData.append("file", blob, "ActiveSheet.pdf");
formData.append("recipientEmail", recipientEmail);
formData.append("optionalMessage", optionalMessage || "");
console.log(" FORM DATA:"+ formData)
// THIS IS DUMMY CODE ... ignore.
//Insert endpoint api here and form Data.
// fetch("/api/email/send-sheet", {
// method: "POST",
// body: formData
// })
// .then(r => {
// //Per current convention this is a 201 Status but the ok is looking for 2XX
// // we can get precise return val with r.status.
// 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.");
},
{
// Only export the active sheet, not the whole workbook
sheetIndex: activeIndex,
// (Optional) PDF metadata
title: "Active Sheet",
author: "SpreadJS",
subject: "Exported from Designer",
keywords: "SpreadJS, PDF"
}
);
}
I am getting an error thrown:
Uncaught TypeError: Cannot read properties of undefined (reading ‘landscape’)
at sendActiveSheetAsPdf (emailbutton.js:200:60)
at init.click (index.html:465:21)
at init.trigger (kendo.custom.min.js:5:4952)
at init._click (kendo.custom.min.js:29:1644)
at HTMLButtonElement.dispatch (jquery-3.4.1.min.js:2:42571)
at v.handle (jquery-3.4.1.min.js:2:40572)
I am guessing this code is wrong or invalid:
pi.orientation(GC.Spread.Sheets.Print.PrintOrientation.landscape);
The order of my SpreadJS java script files on my index.html is:
<!--CSS files-->
<link rel="stylesheet" href="css/default-ocean-blue.css" type="text/css" />
<link href="css/gc.spread.sheets.18.0.0.css" rel="stylesheet" type="text/css" />
<link href="css/gc.spread.sheets.designer.18.0.0.min.css" rel="stylesheet" type="text/css" />
<link href="css/default-ocean-blue.css" rel="stylesheet" type="text/css" />
<link href="FontAwesome/font-awesome-4.7.0/css/font-awesome.min.css" type="text/css" />
<link href="css/site.css" rel="stylesheet" type="text/css" />
<!-- KENDO STUFF -->
<!-- <script src="scripts/jszip.min.js" type="text/javascript"></script> -->
<!--KENDO STUFF:-->
<script src="jQuery/jquery-3.4.1.min.js" type="text/javascript"></script>
<script src="scripts/jszip.min.js" type="text/javascript"></script>
<script src="Kendo/kendo.custom.min.js" type="text/javascript"></script>
<script src="./kendo-ui-license.js" type="text/javascript"></script>
<!--Spread JS Script files-->
<script src="scripts/gc.spread.sheets.all.18.0.0.min.js" type="text/javascript"></script>
<script src="scripts/gc.spread.sheets.shapes.18.0.0.min.js" type="text/javascript"></script>
<script src="scripts/gc.spread.sheets.charts.18.0.0.min.js" type="text/javascript"></script>
<script src="scripts/gc.spread.sheets.io.18.0.0.min.js" type="text/javascript"></script>
<script src="scripts/gc.spread.sheets.print.18.0.0.min.js" type="text/javascript"></script>
<script src="scripts/gc.spread.sheets.pdf.18.0.0.min.js" type="text/javascript"></script>
<!-- <script src="scripts/gc.spread.excelio.18.0.0.min.js" type="text/javascript"></script> -->
<!--SpreadJS Designer Script files-->
<script src="scripts/gc.spread.sheets.designer.resource.en.18.0.0.min.js"></script>
<script src="scripts/gc.spread.sheets.designer.all.18.0.0.min.js"></script>
Seems like when I comment the code out that does the settings the PDF conversion works fine (I am not seeing any errors or exceptions thrown).
Thanks!
George
