0

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

enter image description here

  • 1
    Post a https://stackoverflow.com/help/minimal-reproducible-example where we can see what data you feed into your template and not a "out of the wild" code snippet from your application. A guess in the wild. Embedded the image as base64 encoded string. – Marc Jul 25 '22 at 14:11
  • Oky, i'm go post new question with informations – Carlos Eduardo Jul 25 '22 at 15:11
  • No, just edit your question. – Marc Jul 25 '22 at 15:21

0 Answers0