img display only white blank squere after convert html to pdf

281 Views Asked by At

When i convert my html to pdf using html-pdf moudle on windows, my img tag display only white squere like this

enter image description here

why this is happening? my code is very basic

module.exports = (formData) => {
    const today = new Date();

    return `

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>My First Heading</h1>
<img src="file:///C:/Users/User/Desktop/htmlIWithPdf/assets/bth.png" border="1" width="100" height="100" >

<p>My first paragraph.</p>

</body>
</html>

`
}

my moudle that i use to convert the html to pdf :

const pdf = require("html-pdf");
const fs = require("fs");
const pdfCreate = (req, res, next) => {
  const pdfTemplate = require("./index");
  var options = { format: "A4", orientation: "portrait" };

  pdf.create(pdfTemplate(), options).toStream(function (err, stream) {
    if (err) return next(err);

    stream.pipe(fs.createWriteStream("./foo.pdf"));

    // res.status(200);
    // res.send("Success");
  });
};

// module.exports.pdfCreate = pdfCreate;

pdfCreate()
1

There are 1 best solutions below

1
On

Try replace forward slashes with back slashes: <img src="file:\\\C:\\Users\\User\\Desktop\\htmlIWithPdf\\assets\\bth.png" border="1" width="100" height="100" >