Search code examples
node.jswkhtmltopdf

Use node-wkhtmltopdf with HTML in memory


I am trying to convert HTML into a PDF, but the HTML is generated dynamically and never actually served up. I've been using node-html-pdf but it has some issues I've found difficult to overcome (known, long-standing bugs).

I thought I'd give wkhtmltopdf (via node-wkhtmltopdf) a try, but it expects a URL.

My current thought (which isn't great) is to expose the HTML via express since I'm already exposing a REST API with this server. While doing this isn't rocket science, it seems pretty complicated to just hand something content from memory.

Does anyone have a good pattern for using wkhtmltopdf from node with HTML held in memory?


Solution

  • Apparently there are two npm packages for this. If you google 'node wkhtmltopdf' you are likely to run into this one first: node-wkhtmltopdf

    ...but if you look further you'll find: wkhtmltopdf which is seems more actively maintained and has documentation explaining how to use it directly, as mentioned by @Ben Fortune in the comments above.

    Using the correct package, it seems well explained how to use HTML directly.