I'm creating an HTML via EJS and npm HTML-PDF, to convert to PDF, using NODEJS and MYSQL to pull data from the database.
However, I am not able to display the image, the image is hosted on the same server but in the REACTJS folder, ../html/static/media/... and the code is in ../server/..
follow the code and the result of the PDF
<!DOCTYPE html>
<html lang="pt">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width:device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Imóvel <%= name %></title>
</head>
<body>
<section id="header">
<h1>Immobile</h1>
<img src='<%= img %>' />
<h2><%= name %></h2>
</section>
</body>
</html>
Code of creator PDF
let img = media[0].url;
const name = immobile[0].name
ejs.renderFile("./immobile/pdf/index.ejs", {name:name, img:img}, (err, html) => {
if (err) {
console.log("error: " + err);
} else {
pdf.create(html, {}).toFile("../html/static/media/immobile.pdf", (err,response) => {
if (err) {
console.log("Um erro aconteceu: " + err);
} else {
res.json({"success":"true","url":"" + response.filename + ""});
}
});
}
});
Follow the print image