Szpadel/chrome-headless-render-pdf

When chromeBinary path has spaces in it

Closed this issue · 3 comments

When the chrome binary path has spaces in it the file location does not appear to be found by default or when the file location is explicitly passed in. For example:

const RenderPDF = require('chrome-headless-render-pdf');
RenderPDF.generateMultiplePdf([
{url:'http://google.com',pdf:'C:\Users\Your Name\Desktop\outputPdf.pdf', chromeBinary:'C:\Program Files (x86)\Google\Chrome\Application\'}
]).then(function(args){
console.log(args);
}, function(err){
console.log(err);
});

Results in:

Error: Couldn't detect chrome version installed! use --chrome-binary to pass custom location
at RenderPDF.detectChrome (C:\dev\paylockReportRunner\node_modules\chrome-headless-render-pdf\index.js:282:15)
at process._tickCallback (internal/process/next_tick.js:109:7)

Obviously I'm on Windows. Specifically W10 and Chrome 68, both 64-bit. I tried replacing the \ with / but the result is the same. I also tried explicitly adding in the chrome.exe but still the same result. This led me to the conclusion that it was the spaces in the path. Suggestions?

You should pass escaped path to chrome binary.
But you should pass chromeBinary parameter in object in second argument.

so it should be more or less:

RenderPDF.generateMultiplePdf([
    {url:'http://google.com',pdf:'C:\\Users\\Your\ Name\\Desktop\\outputPdf.pdf'}
], {
    chromeBinary:'C:\\Program\ Files\ (x86)\\Google\\Chrome\\Application\\chrome.exe'
})

Ah... I did not think to try that. Works perfectly! Thanks!

sb39 commented

@mbielski any thoughts on how to get this done on a lambda function ?