- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 07:12 PM
Hello,
I have a button on KB article portal page to download the article to pdf. The problem I have is that some articles do not export images to pdf whereas a few are exported with images. There is no difference between these articles in the way the images are embedded.
Here is the script I am using. (widget is modified accordingly)
kbArticleDownload: function() {
var kbID = this.getParameter('sysparm_kbID');
var kbContent = '';
var kb = new GlideRecord("kb_knowledge");
if (kb.get(kbID)) {
kbContent = kb.number.fontsize(5).bold() + ' : ' + kb.short_description.fontsize(5).bold();
kbContent += "\n\n"+ kb.text.toString();
var fileName = kb.number + '_' + kb.getValue('short_description');
}
var sysAtt = new GlideRecord('sys_attachment');
sysAtt.addEncodedQuery("table_sys_id="+kbID+"^file_nameSTARTSWITH"+kb.number+"_"+"^content_type=application/pdf");
sysAtt.query();
while (sysAtt.next()) {
sysAtt.deleteRecord(); // Each export attaches a pdf to article. Delete the existing attachment before exporting a new copy.
}
var expt = new sn_pdfgeneratorutils.PDFGenerationAPI;
var result = expt.convertToPDFWithHeaderFooter(kbContent, "kb_knowledge", kbID, fileName);
return '/sys_attachment.do?sys_id=' + result.attachment_id;
},
Has someone used this feature and got it working with no issues? Can you suggest what could be the issue?
Regards,
Viji
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 12:10 AM
I tried replacing html string to desired path before exporting. Using this piece of code before calling the PDFGeneration API in the above script.
var gsa = new GlideSysAttachment();
var agr = gsa.getAttachments('kb_knowledge', kbID);
while (agr.next()) {
kbContent = kbContent.replace(
'<img src="/sys_attachment.do?sys_id=','<img src="sys_attachment.do?sys_id=');
}
This is exporting with images. I will do more tests and confirm so that others can make use of this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Do you have the full working code for this? We have been asked recently to add a Print KBA button to the service portal which is to generate a PDF .