pofider / phantom-html-to-pdf

Highly scalable html to pdf conversion using phantom workers
MIT License
159 stars 33 forks source link

Custom Headers is not working #98

Open chinkan opened 6 years ago

chinkan commented 6 years ago

Hi, I have tried the to push the customHeaders into global config or inside conversion option but still found that no custom headers received from server. My code is something like below:

 var conversion = require("phantom-html-to-pdf")({
            timeout: 120000,
            waitForJS: true,
            waitForJSVarName: "PHANTOM_HTML_TO_PDF_READY",
            printDelay: 5000,
            customHeaders: { //put here is not working
                "Authorization": token[0]
            }
        });

 conversion({
            url: url,
            footer: '<div style="font-family: \'Source Sans Pro\',sans-serif;text-align:center">Page&nbsp{#pageNum}&nbspof&nbsp{#numPages}</div>',
            customHeaders: { //put here is also not working
                "Authorization": token[0]
            }
        }, function (err, pdf) {
            console.log("err => " + err);
            console.log("pdf => " + pdf);
            var output = fs.createWriteStream(path)
            console.log(pdf.logs);
            console.log(pdf.numberOfPages);
            // since pdf.stream is a node.js stream you can use it
            // to save the pdf to a file (like in this example) or to
            // respond an http request.
            pdf.stream.pipe(output);

            callback(null, path);
        });

How can i done this? thanks!