0

I am using HTML-pdf library to convert HTML page into pdf. I am getting the dynamic part on the pdf however the image is reportedly missing. I have tried to use all methods at my disposable, however, the image isn't appearing in the generated pdf. What should I do? Below is my HTML template:

<head>
    <title>Certificate</title>
    <!-- <link rel="stylesheet" href="../stuff/certificate.css"> -->
    <style>
        html,
body {
      height: 100%;
      width: 100%;
      }


img{
    height: 100%;
    width: 100%;
    margin:0px;
    }

    #name{
    margin-top:-420px;
    margin-left: 60px;
    }

  p{
    font-size:40px;
    color:black;
    font-weight:400;
    text-align: center;
  }
</style>
</head>
<body>
    <img src="../stuff/certificate.jpg">
    <div id="name"><p><%=name%></p></div>
</body>
</html>

I am getting the name as per my wish, however the image isn't appearing at all. Kindly help. The image is in different folder as compared to the html one.

  • Did you try to follow the example as shown in the [GitHub repository](https://github.com/marcbachmann/node-html-pdf/blob/master/examples/businesscard/test.js)? – Roy May 19 '20 at 20:16
  • yes I did, I changed the src of img to "", however it also failed. – Insignificant_guy May 19 '20 at 20:46

1 Answers1

1

Try to use a JS library that detect when images have been loaded.

You can use it like this:

<script src="https://npmcdn.com/imagesloaded@4.1/imagesloaded.pkgd.min.js"></script>

<script type="text/javascript">
  imagesLoaded(document.body, function() {
    window.print();
  });
</script>
Uday
  • 464
  • 3
  • 11