Export KB Article as PDF

Kasi Ramanathan
Kilo Guru

Hi,

@AnirudhKumar 

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.

find_real_file.png

1 ACCEPTED SOLUTION

Pranesh072
Mega Sage
Mega Sage

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);
	}

 

find_real_file.png

 

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;
    }

});

https://community.servicenow.com/community?id=community_question&sys_id=72f14c67dbd0bc904819fb243996...

View solution in original post

26 REPLIES 26

Pranesh072
Mega Sage
Mega Sage

You can try the print(ctrl+P) functionality.

 

or

 

You have to clone the Knowledge Article Content widget and add following code in html

 

<li class="kb-menu-entry" ><a href="" onclick="window.print()"><i class="fa fa-print" aria-hidden="true"></i>  Print</a></li>

 

find_real_file.png

 

Behavior

find_real_file.png

 

Hi @Pranesh,

 

I need the similar function to the Export from native view.

find_real_file.png

@Kasi Ramanathan 

for native view you can use client side UI action on the knowledge article table

Client - True

OnClick - printPage();

Script:

function printPage(){

printList('25000');   

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

Thanks for you help. But the requirement is to get it from Service Portal as "Export as PDF" action to be added below "EDIT"

find_real_file.png