Turn HTML into PDF with Node.js

Regos Dev Studio
1 min readMay 16, 2019

--

As the title says, today’s post is about how to generate a PDF file based on HTML content, all in Node.js.

To generate PDF files for reports or downloadable content is very common in a certain type of applications where those documents play the role of reports or receipts for a transaction. Unfortunately, while some documents are basically plain text, others require a more complex structure to display all that data. If that’s the case, you can get help with HTML and transform that into a PDF file.

What we are going to need:

  • node.js
  • pug (npm package)
  • html-pdf (npm package)

Here is an example of how you can transform your data into a PDF file easily.

Here we take advantage of the versatility provided by pug to render a template based on arbitrary data and then use html-pdf to write that content into a PDF file.

This strategy has worked great for us in recent projects and we wanted to share it with you. Please let us know if this worked for your or share in the comments the way you do similar things!

Regos Dev Studio is a product development company that builds add-ons for Jira and Confluence, combined with the development of custom solutions in a variety of languages.

Don’t forget to check out our website, visit our Atlassian marketplace listing. You can also follow us on Twitter or LinkedIn and stay tuned for updates!

--

--