
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2021 10:53 PM
Hi,
Kindly help me to export KB article as PDF. I need a button called Export as PDF in kb_article page which will export the repective KB article as PDF.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2021 05:47 AM
You can use the same script include provided.
Add the following lines in your html and client script on the clone Knowledge Article Content widget
<li class="kb-menu-entry" ><a href="" ng-click="c.exportThisArticle()"><i class="fa fa-print" aria-hidden="true"></i> Print</a></li>
c.exportThisArticle=function()
{
var ga = new GlideAjax('DownloadPDFCustom');
ga.addParam('sysparm_name' , 'kbArticleDownload');
ga.addParam('sysparm_kbID',c.data.article_sys_id);
ga.getXML(getResponse);
}
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
window.open(answer);
}
Script Include
var DownloadPDFCustom = Class.create();
DownloadPDFCustom.prototype = Object.extendsObject(AbstractAjaxProcessor, {
kbArticleDownload: function() {
var kbID = this.getParameter('sysparm_kbID');
var kbContent = '';
var kb = new GlideRecord("kb_knowledge");
if (kb.get(kbID)) {
kbContent = kb.text.toString();
}
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
var result = v.convertToPDF(kbContent, "kb_knowledge", kbID, kb.getValue('short_description')); //updated the title of pdf
return '/sys_attachment.do?sys_id=' + result.attachment_id;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2021 05:14 AM
Hi,
function exportPDF() {
var sysparm_table = g_form.getTableName(); //get Incident Table
var sysparm_sys_id = g_form.getUniqueValue().toString(); //Open record+Sys_id
var instanceName = 'https://instancename.service-now.com/'; //Instance Name stored in variable
var url = instanceName + sysparm_table + '.do?PDF&sys_id=' + sysparm_sys_id;
g_navigation.openPopup(url); //download file in PDF
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2021 05:23 AM
Hi Kasi,
you can use this function for exporting to PDF,
function exportMyPage2PDF() {
var dialog = new GwtPollDialog('/your_script.do?sysparm_proj=${sysparm_proj}', JSON.stringify(null), 0, '', 'whtpexport');
dialog.on('beforeclose', function() {
window.setTimeout(function() {
$j('.download-report').focus();
}, 100);
});
dialog.execute();
}
Kindly mark helpful and mark as correct answer if it solves your query.
Thanks,
Priyatham.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2021 05:47 AM
You can use the same script include provided.
Add the following lines in your html and client script on the clone Knowledge Article Content widget
<li class="kb-menu-entry" ><a href="" ng-click="c.exportThisArticle()"><i class="fa fa-print" aria-hidden="true"></i> Print</a></li>
c.exportThisArticle=function()
{
var ga = new GlideAjax('DownloadPDFCustom');
ga.addParam('sysparm_name' , 'kbArticleDownload');
ga.addParam('sysparm_kbID',c.data.article_sys_id);
ga.getXML(getResponse);
}
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
window.open(answer);
}
Script Include
var DownloadPDFCustom = Class.create();
DownloadPDFCustom.prototype = Object.extendsObject(AbstractAjaxProcessor, {
kbArticleDownload: function() {
var kbID = this.getParameter('sysparm_kbID');
var kbContent = '';
var kb = new GlideRecord("kb_knowledge");
if (kb.get(kbID)) {
kbContent = kb.text.toString();
}
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
var result = v.convertToPDF(kbContent, "kb_knowledge", kbID, kb.getValue('short_description')); //updated the title of pdf
return '/sys_attachment.do?sys_id=' + result.attachment_id;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2021 05:59 AM
Updated the html for button text
<li class="kb-menu-entry" ><a href="" ng-click="c.exportThisArticle()"><i class="fa fa-print" aria-hidden="true"></i> Export to PDF</a></li>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 12:24 AM
I could see the images are not getting exported to PDF. Is there any specific reason for it?
Also, Kindly suggest me is there any way to export image also with the PDF.
Thanks in advance!!