How to avoid page break while generating PDF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2018 12:48 AM
Hi Team,
I am trying to generate home page in PDF.
I am getting PDF in to email but I am facing page break issue as shown in below fig.. Please suggest how to over come this. And also i used script include to generate this PDF, please find my script include code as below.
Script include code:
var DashboardScheduler = Class.create();
DashboardScheduler.prototype = {
ENDPOINT : 'sys_confirm_whtp.do',
REPORT : '/home.do?sysparm_userpref_homepage=dd20946edbe463801d398edf4b961905',
RECIPIENTS : '',
ORIENTATION : 'Landscape',
PAPERSIZE : 'Letter',
SMART_SHRINK : true,
AVOID_PAGE_BREAK : true,
ZOOM_FACTOR : 100,
ORIENTATIONS : {
'landscape' : 'Landscape',
'portrait' : 'Portrait'
},
PAPERSIZES : {
'letter' : 'Letter',
'a3' : 'A3',
'a4' : 'A4',
'a5' : 'A5'
},
G_CK: '',
initialize: function(report, recipients) {
this.setReport(report);
this.setRecipients(recipients);
this.G_CK = gs.getSession();
},
getEndpoint: function() {
return "https://" + gs.getProperty('instance_name') + ".service-now.com/" + this.ENDPOINT;
},
setReport: function(report) {
if (this.isValidPage(report)) {
this.REPORT = "/home.do?sysparm_view=" + report;
}
},
isValidPage: function(report) {
var page = new GlideRecord('sys_portal_page');
page.addEncodedQuery('sys_class_name=sys_portal_page^view=' + report);
page.query();
if (page.next()) {
return true;
}
return false;
},
setRecipients: function(recipients) {
this.RECIPIENTS = recipients;
},
setOrientation: function(orientation) {
if (this.isValidOrientation(orientation)) {
this.ORIENTATION = orientation;
}
},
setPapersize: function(size) {
if (this.isValidSizeValue(size)) {
this.PAPERSIZE = size;
}
},
setSmartShrink: function(smartShrink) {
if (typeof smartShrink == 'boolean') {
this.SMART_SHRINK = smartShrink;
}
},
setAvoidPageBreakInside: function(avoidPageBreak) {
if (typeof avoidPageBreak == 'boolean') {
this.AVOID_PAGE_BREAK = avoidPageBreak;
}
},
setZoomFactor: function(zoomFactor) {
if (typeof zoomFactor == 'number' && zoomFactor > 0 && zoomFactor < 101) {
this.ZOOM_FACTOR = zoomFactor;
}
},
encodeBody: function() {
var query = JSON.stringify({"dataDocType":true,"orientation":this.ORIENTATION,"papersize":this.PAPERSIZE,"smartShrink":this.SMART_SHRINK,"avoidPageBreakInside":this.AVOID_PAGE_BREAK,"zoomFactor": this.ZOOM_FACTOR});
var total = "sysparm_ck=" + this.G_CK + "&sysparm_target=" + this.REPORT + "&email=" + this.RECIPIENTS + "&sysparm_query=" + query;
var encodedA = encodeURIComponent(total).replace(/%(\d)a/g, "%$1A");
var encodedB = encodedA.replace(/%(\d)b/g, "%$1B");
var encodedC = encodedB.replace(/%(\d)c/g, "%$1C");
var encodedD = encodedC.replace(/%(\d)d/g, "%$1D");
var encodedE = encodedD.replace(/%(\d)e/g, "%$1E");
var encodedF = encodedE.replace(/%(\d)f/g, "%$1F");
var encodedG = encodedF.replace(/%3D/gmi, "=");
return encodedG.replace(/%26/gmi, "&");
},
isValidSizeValue: function(size) {
return (size == this.PAPERSIZES.letter ||
size == this.PAPERSIZES.a4 ||
size == this.PAPERSIZES.a5 ||
size == this.PAPERSIZES.a3) ? true : false;
},
isValidOrientation: function(orientation) {
return (orientation == this.ORIENTATIONS.landscape ||
orientation == this.ORIENTATIONS.portrait) ? true : false;
},
makeRequest: function() {
var message = new sn_ws.RESTMessageV2();
message.setEndpoint(this.getEndpoint());
message.setHttpMethod('post');
message.setBasicAuth('radhika.bollineni', 'Radhika@123');
message.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
message.setRequestBody(this.encodeBody());
var response = message.execute();
return response.getStatusCode();
},
'type' : 'DashboardScheduler'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2018 09:39 PM
any input will be help full.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2019 11:31 AM
Hi radhi's,
there are 3 typos in JSON parameters:
JSON.stringify({"dataDocType":true,"orientation":this.ORIENTATION,"papersize":this.PAPERSIZE,"smartShrink":this.SMART_SHRINK,"avoidPageBreakInside":this.AVOID_PAGE_BREAK,"zoomFactor": this.ZOOM_FACTOR});
Correct parameters list:
{"dataDoctype":true,"paperSize":"Letter","zoomFactor":"100","orientation":"landscape","smartShrink":true,"avoidPageBreakInside":true}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2019 12:23 PM
Hi Radhi,
If i am not wrong then instead of page break the main issue is that graphs are being broken into 2 pages which is distorting the report view as page properties of A3/A4 will be still same. Could you please Webkit HTML to PDF plugin is activated?
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2021 06:44 PM
Hi,
How can you export Dashboard to pdf with your include script? I try your code with $pa_dashboard.do, but it return a empty file (Don't have any data write in there). Can you help me?
Thanks!!
My source code:
ENDPOINT: 'sys_confirm_whtp.do',
REPORT: '/$pa_dashboard.do?sysparm_dashboard=39785ea31b31301081dd7596cc4bcb9c',
RECIPIENTS: 'trinhdinhhuy0210@gmail.com',
G_CK: '',
initialize: function() {
this.G_CK = gs.getSession();
},
getEndpoint: function() {
return "https://" + gs.getProperty('instance_name') + ".service-now.com/" + this.ENDPOINT;
},
encodeBody: function() {
var query = JSON.stringify({
"dataDoctype":true,
"paperSize":"Letter",
"zoomFactor":"100",
"orientation":"landscape",
"smartShrink":true,
"avoidPageBreakInside":true
});
var total = "sysparm_target=" + this.REPORT + "&email=" + this.RECIPIENTS + "&sysparm_query=" + query;
var encode = encodeURI(total);
return encode;
},
makeRequest: function() {
var message = new sn_ws.RESTMessageV2();
message.setEndpoint(this.getEndpoint());
message.setHttpMethod('post');
message.setBasicAuth('huytd', 'huy@123');
message.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
message.setRequestBody(this.encodeBody());
var response = message.execute();
return response.getStatusCode();
},