0

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.

0

1 Answer 1

0

The latest version of WkHtmltoX was now over 5 years ago.

Stable series is 0.12.6, which was released on June 11, 2020

The app was described as not suited to web usage without sandboxing, and had many known problems, since based on a 2015 QT4 code base. Many forks have appeared and disappeared too, as hard to rectify problems, such as reliable scaling and image embedding.

The recommendation is to use a browser compatible web HTML 2 PDF workflow as well supported by Chrome-Headless-Shell or similar.

Mothballed in 2023 the Authors recommendations are

Recommendations Do not use wkhtmltopdf with any untrusted HTML – be sure to sanitize any user-supplied HTML/JS, otherwise it can lead to complete takeover of the server it is running on! Please consider using a Mandatory Access Control system like AppArmor or SELinux, see recommended AppArmor policy.

If you’re using it for report generation (i.e. with HTML you control), also consider using WeasyPrint or the commercial tool Prince – note that I’m not affiliated with either project, and do your diligence.

If you’re using it to convert a site which uses dynamic JS, consider using puppeteer or one of the many wrappers it has.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.