Node-html-pdf: Problem with external URLs

Created on 5 Oct 2017  路  8Comments  路  Source: marcbachmann/node-html-pdf

<html>
<head>
<style>
    body {
        background-image: url("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png");
        background-color: #ccc;
    }
</style>
</head>
<body>
    <div>sample div</div>
</body>
</html>

When I use this and store in html file, and run html-pdf from command line it works I see properly rendered pdf file, if I send that to pdf over nodejs like:

// 
...
    pdf.create(html, {
            format: 'letter',
            border: {
                top: '0.6in',
                right: '0.6in',
                bottom: '0.6in',
                left: '0.6in'
            }
        }).toFile(`./tmp/${fileName}`, function (error, response) {
            if (error) {
                console.log(error);
                future.return(error);
            } else {
                const file = fs.readFileSync(response.filename);
                base64String = new Buffer(file).toString('base64');
                fs.unlink(response.filename);
                future.return(base64String);
            }
        });

basically this doesn't work only when html contains remote URLs, if I remove remote URLs from code it works. Is there any further parameter which will allows reading of remote URLs or?

Most helpful comment

@marcbachmann yeah have slow connection here only 150Mbit/s lol.
I found what is the issue basically this is issue with Meteor privileges and phantomjs, some weird issue which I'm investigating, it works in debug mode of app but not in regular startup.

However would like to thanks for help, tool is great!

All 8 comments

Weird issue. Could you try to delay the rendering a bit. There鈥檚 a new option named renderDelay for that.
I assume that the network is slower and phantomjs doesn鈥檛 wait for images in css to be loaded.

@marcbachmann yeah have slow connection here only 150Mbit/s lol.
I found what is the issue basically this is issue with Meteor privileges and phantomjs, some weird issue which I'm investigating, it works in debug mode of app but not in regular startup.

However would like to thanks for help, tool is great!

@marcbachmann I found another issue, I send html string to create function, as part of html is style where I have full path URL for example like this one http://www.pngmart.com/files/4/Earth-PNG-Image.png and there is a class which have that as background-image, after printing pdf have blank background instead to have this image...I wonder is there only way to render properly with images is to set base file location from where it will pull images or?

@vaske Did you ever manage to solve this? We're also running into images not being rendered in the pdf anymore with our Meteor setup.

@kkor nope, we left it and made our own pdf server for such stuff, it was long time ago :)

Thanks for the fast reply, let's see if I can fix ours :)

Hi @vaske

I have a prolem when render gmap here
image

I used code
````
pdf.create(htmlPageOne, _.merge({}, options, { orientation: 'landscape' })).toStream(function(err, stream){

        let ws = stream.pipe(fs.createWriteStream(tmpPath + '/' + outputName + '_one.pdf'));
        ws.on('finish', function () {

        });


      })

````
Can you help me it's same your issue?

@phanthinh nope I didn't have that kind of issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tsp1996 picture tsp1996  路  5Comments

sca88 picture sca88  路  4Comments

aminjoharinia picture aminjoharinia  路  4Comments

B-StS picture B-StS  路  5Comments

cmoulliard picture cmoulliard  路  3Comments