src/pdf.js
/********************************************************************
    * WARNING: DISABLE EMBEDDED JAVASCRIPT WHEN RUNNING CHROME INSTANCE *
    ********************************************************************/
DISABLE EMBEDDED JAVASCRIPT WHEN RUNNING CHROME INSTANCE
DISABLE EMBEDDED JAVASCRIPT WHEN RUNNING CHROME INSTANCE
chromeMethod(filePath, html, options, callback) {
        var chromeOptions = {};
        chromeOptions["port"] = port;
        var header;
        var footer;
        var margin;
        if(options) {
            header = options["header"];
            footer = options["footer"];
            margin = options["margin"];
        }
        if((header && header.length > 0) || (footer && footer.length > 0)) {
            var printOptions = {};
            printOptions["displayHeaderFooter"] = true;
            if(header && header.length > 0) {
                    Logger.debug("Pdf::create() Using header");
                printOptions["headerTemplate"] = header;
            }
            if(footer && footer.length > 0) {
                    Logger.debug("Pdf::create() Using footer");
                printOptions["footerTemplate"] = footer;
            }
            if(margin) {
                var marginLeft = margin["left"];
                if(marginLeft) {
                    printOptions["marginLeft"] = marginLeft;
                }
                var marginTop = margin["top"];
                if(marginTop) {
                    printOptions["marginTop"] = marginTop;
                }
                var marginRight = margin["right"];
                if(marginRight) {
                    printOptions["marginRight"] = marginRight;
                }
                var marginBottom = margin["bottom"];
                if(marginBottom) {
                    printOptions["marginBottom"] = marginBottom;
                }
            }
            chromeOptions["printOptions"] = printOptions;
        }
        ChromePdf.create(html, chromeOptions).then((pdf) => {
            var promise = pdf.toFile(filePath);
            promise.then((res) => {
                Logger.debug("Pdf::create() Created PDF: " + filePath);
                callback(true, filePath);
            });
            promise.catch((err) => {
                Logger.error("Pdf::create() Unable to create PDF: ", err);
                callback(false, null);
            });
        });
    }
chromeMethod ( filePath , html , options , callback ) { var chromeOptions = { } ; chromeOptions [ "port" ] = port ; var header ; var footer ; var margin ; if ( options ) { header = options [ "header" ] ; footer = options [ "footer" ] ; margin = options [ "margin" ] ; } if ( ( header && header . length > 0 ) || ( footer && footer . length > 0 ) ) { var printOptions = { } ; printOptions [ "displayHeaderFooter" ] = true ; if ( header && header . length > 0 ) { Logger . debug ( "Pdf::create() Using header" ) ; printOptions [ "headerTemplate" ] = header ; } if ( footer && footer . length > 0 ) { Logger . debug ( "Pdf::create() Using footer" ) ; printOptions [ "footerTemplate" ] = footer ; } if ( margin ) { var marginLeft = margin [ "left" ] ; if ( marginLeft ) { printOptions [ "marginLeft" ] = marginLeft ; } var marginTop = margin [ "top" ] ; if ( marginTop ) { printOptions [ "marginTop" ] = marginTop ; } var marginRight = margin [ "right" ] ; if ( marginRight ) { printOptions [ "marginRight" ] = marginRight ; } var marginBottom = margin [ "bottom" ] ; if ( marginBottom ) { printOptions [ "marginBottom" ] = marginBottom ; } } chromeOptions [ "printOptions" ] = printOptions ; } ChromePdf . create ( html , chromeOptions ) . then ( ( pdf ) => { var promise = pdf . toFile ( filePath ) ; promise . then ( ( res ) => { Logger . debug ( "Pdf::create() Created PDF: " + filePath ) ; callback ( true , filePath ) ; } ) ; promise . catch ( ( err ) => { Logger . error ( "Pdf::create() Unable to create PDF: " , err ) ; callback ( false , null ) ; } ) ; } ) ; }
WARNING: DISABLE EMBEDDED JAVASCRIPT WHEN RUNNING CHROME INSTANCE
WARNING : DISABLE EMBEDDED JAVASCRIPT WHEN RUNNING CHROME INSTANCE