I'm using wkhtmltopdf in a Node.js/Express application with a Python PDF generation script. I've encountered an issue where images and page numbers aren't appearing in the generated PDFs, although my header.html and footer.html files are being correctly added to the document.
What works: Header and footer HTML files are correctly being incorporated into the PDF The basic HTML content is rendering properly PDF files are being generated and saved successfully
What doesn't work: Images in the HTML content aren't showing up in the final PDF Page numbers ( and ) in the footer aren't being rendered
My setup: footer.html contains:
<div class="footer">
<span class="left">© 2025 <a href="https://leanstack.me">leanstack.me</a> All rights reserved.</span>
<span class="right">Page <span class="page"></span> of <span class="topage"></span></span>
</div>
header.html uses:
<div class="header">
<img src="https://945f0bc1-1beb-46ba-b4ed-8b74bc579746-00-3tynn012wsw1z.janeway.replit.dev:5000/images/leanstack-main-logo.png" alt="Leanstack Logo">
</div>
My Python PDF generation code:
class PDFGenerator:
def __init__(self):
self.config = pdfkit.configuration(wkhtmltopdf='/nix/store/n6zynih08kfi8dkkdpizmlq77j7kyk1i-wkhtmltopdf-bin-0.12.6-3/bin/wkhtmltopdf')
self.options = {
'quiet': '',
'print-media-type': '',
'page-size': 'Letter',
'margin-top': '20mm',
'margin-right': '20mm',
'margin-bottom': '20mm',
'margin-left': '20mm',
'encoding': 'UTF-8'
}
def generate_pdf(self, html_content, output_path=None):
# PDF generation code...
What I've tried:
- Using both relative and absolute URLs for images
- Adding the header and footer via command line arguments
- Checking that images are accessible via browser
Environment:
- wkhtmltopdf 0.12.6-3
- Running on Replit with Node.js and Python
- Using pdfkit Python library
How can I get the images and page numbers to display correctly in my PDF while maintaining the working header/footer functionality?
What I've tried:
- Using both relative and absolute URLs for images
- Adding the header and footer via command line arguments
- Checking that images are accessible via browser
Expecting: PDF report to have images including logo and page numbers (Page 1 of 5, etc.) generating in the header and footer of the PDF report.