Published KB article export to PDF (Issue with image size)

Ramya95
Tera Contributor

We have a requirement like to export all published KB articles to PDF format. We are able to download the KB article to pdf format using background script which i mentioned below. But the issue is the image which is present in KB article is not fully captured in PDF(Half of the image got cropped). Could someone suggest what changes can we make to capture entire image from KB article to PDF.
Code:

var exportedArticles = <sys_id of a knowledge article to drop the PDFs into>

var current = new GlideRecord("kb_knowledge");

current.addEncodedQuery('workflow_state=published');

current.query();

while (current.next())

{

var header = 'Number: ' + current.number.getDisplayValue() + ' <br/> ';

header += 'Knowledge Base: ' + current.kb_knowledge_base.getDisplayValue() + ' <br/> ';

header += 'Category: ' + current.kb_category.getDisplayValue() + ' <br/> ';

header += 'Title: ' + current.short_description.getDisplayValue() + '<br/>';

var html = header + current.text.toString();

var filename = current.kb_knowledge_base.getDisplayValue() + '-' + current.kb_category.getDisplayValue() + ' - ' + current.number.getDisplayValue();

var v = new sn_pdfgeneratorutils.PDFGenerationAPI;

var result = v.convertToPDF(html, "kb_knowledge", exportedArticles, filename);

}

Thanks in Advance

2 REPLIES 2

Rafael Batistot
Kilo Patron

Hi @Ramya95 

i tried this scrip via Script include + background script

var KBToPDFExport = Class.create();
KBToPDFExport.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    exportAllPublished: function(exportedArticles) {
        var gr = new GlideRecord("kb_knowledge");
        gr.addEncodedQuery('workflow_state=published');
        gr.query();

        while (gr.next()) {
            var header = 'Number: ' + gr.number.getDisplayValue() + ' <br/>';
            header += 'Knowledge Base: ' + gr.kb_knowledge_base.getDisplayValue() + ' <br/>';
            header += 'Category: ' + gr.kb_category.getDisplayValue() + ' <br/>';
            header += 'Title: ' + gr.short_description.getDisplayValue() + '<br/>';

            var style = "<style>img { max-width: 100%; height: auto; }</style>";
            var html = style + header + gr.text.toString();

            var filename = gr.kb_knowledge_base.getDisplayValue() + '-' +
                gr.kb_category.getDisplayValue() + ' - ' +
                gr.number.getDisplayValue();

            var v = new sn_pdfgeneratorutils.PDFGenerationAPI();
            var result = v.convertToPDF(html, "kb_knowledge", exportedArticles, filename);
        }

        return "Export completed.";
    },



    type: 'KBToPDFExport '
});

 

var exportador = new KBToPDFExport();
exportador.exportAllPublished('<sys_id of where you want save yours KB>');



var exportador = new KBToPDFExport();
exportador.exportAllPublished('<sys_id of where you want save yours KB>');

 

We are trying to save our published KB article as PDF as attachment in same Kb article.
we are doing a bulk export of all published articles in that case what must be given in place of  ,<sys_id of where you want save yours KB>,.
Thank you.