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.
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>