node-html-pdf not show image in PDF

I am trying generate PDF from simple code, but no show image. Help me please.

code

pdf.create("Hello <img src='j4.jpg' />").toFile('./pdf/cotizacion.pdf', function (err) {
    if (err) {
        console.log(err);
    } else {
        console.log("File created successfully ");
    }
});

Result: enter image description here

Thanks!

Upvotes: 0

Views: 3540

Answers (3)

HYM
HYM

Reputation: 1

are you able to solve this yet? I have experience same issue, but I was able to solve the file:// protocol for local files. for relative path use this> file:///path_to_file (adding an extra lash) instead of this> file://path_to_file

same as the server path

<img src="http:///localhost:3000/images/logo.svg" style="width:100%"/>

instead of

<img src="http://localhost:3000/images/logo.svg" style="width:100%"/>

Upvotes: 0

R.  Barbus
R. Barbus

Reputation: 93

After some testing I noticed the images are shown in pdf if they are served somewhere, every attempt with file://path_to_file or relative path failed.

Instead I serve the image on a server http://localhost:3000/images/logo.svg

and I use <img src="http://localhost:3000/images/logo.svg" style="width:100%"/>

Upvotes: 1

Ashishssoni
Ashishssoni

Reputation: 819

Can you something like this, since its not reading your image, its taking it as a string.

    <img src={{IMG_URL}} style="width:100%"/> 

Or you can put base64 of image like:

<img src="data:image/jpeg;base64, {{BASE64_DATA_OF_IMG}}" style="width:100%"/>

This will read your image in pdf.

Upvotes: 2

Related Questions