- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2025 07:36 AM - edited 07-24-2025 07:38 AM
Hello, I've created a script include and snippet from the widget which pulls through the data on a service portal page.
This works all well and good but I cant for the life of me get it to generate in Landscape not portrait? Any ideas welcome. 😁
//SP SNIPPET
const ga = new GlideAjax("PDFExportHelper");
ga.addParam("sysparm_name", "generatePDF");
ga.addParam("sysparm_html", html);
ga.addParam("sysparm_project", $scope.c.selectedProject);
ga.addParam("sysparm_date", $scope.c.selectedDate);
const selectedRecord = $scope.c.filteredData?.[$scope.c.selectedProject]?.[0];
if (!selectedRecord || !selectedRecord.sys_id) {
console.warn("Missing selected record or sys_id.");
return;
}
ga.addParam("sysparm_record_id", selectedRecord.sys_id);
console.log("Calling server with record ID:", selectedRecord.sys_id);
ga.getXMLAnswer(function (recordSysId) {
console.log("Returned sys_id:", recordSysId);
if (recordSysId) {
$scope.$apply(() => {
$scope.c.pdfGenerated = true;
});
} else {
console.warn("No sys_id returned");
}
});
};
// Script includes
var PDFExportHelper = Class.create();
PDFExportHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
generatePDF: function () {
try {
var html = this.getParameter("sysparm_html");
var project = this.getParameter("sysparm_project");
var date = this.getParameter("sysparm_date");
var recordId = this.getParameter("sysparm_record_id");
if (!recordId) return '';
var today = new GlideDateTime();
var gd = today.getDate();
var ukToday = today.getDayOfMonthLocalTime().toString().padStart(2, '0') + '-' +
(today.getMonthLocalTime()).toString().padStart(2, '0') + '-' +
today.getYearLocalTime();
var parts = date.split('-');
var asOnUK = (parts.length === 3) ? parts[2] + '-' + parts[1] + '-' + parts[0] : 'unknown';
var pdfName = ukToday + ' - ' + asOnUK + '.pdf';
var api = new sn_pdfgeneratorutils.PDFGenerationAPI();
var config = { orientation: 'landscape' };
var attachedToSysId = api.convertToPDF(
html,
"project_status",
recordId,
pdfName,
"",
config
);
if (!attachedToSysId) return '';
return recordId;
} catch (e) {
return '';
}
}
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2025 08:34 AM
try this
PDFGenerationAPI - Scoped, Global
var api = new sn_pdfgeneratorutils.PDFGenerationAPI();
var hfInfo = new Object();
hfInfo["PageOrientation"] = "landscape";
var attachedToSysId = api.convertToPDFWithHeaderFooter(
html,
"project_status",
recordId,
pdfName,
hfInfo
);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2025 08:34 AM
try this
PDFGenerationAPI - Scoped, Global
var api = new sn_pdfgeneratorutils.PDFGenerationAPI();
var hfInfo = new Object();
hfInfo["PageOrientation"] = "landscape";
var attachedToSysId = api.convertToPDFWithHeaderFooter(
html,
"project_status",
recordId,
pdfName,
hfInfo
);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2025 04:07 PM
@Ankur Bawiskar that did the trick! Thanks again!