npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

html-pdf-converter-node

v2.1.1

Published

you can use this package to convert html into pdf,you have to pass html,fileName,onSuccess and onError params, onSuccess,you will get file url and onError,you will get error if any occur while creating pdf.

Readme

HTML to PDF Exporter

A simple Node.js package that converts HTML content to a PDF and saves it to a specified folder. Once saved, the PDF can be accessed via a URL.



Installation

To use the html-to-pdf-exporter package, follow these steps:

1. Install the required dependencies

This package relies on html-pdf-node for PDF generation and dotenv to manage environment variables.

Run the following command to install the necessary packages:

npm install html-pdf-node dotenv

2. Install the package
If you're using it as a standalone package, install it via NPM:

npm install html-to-pdf-exporter

you just have to import convertHTMLTOPDF from "html-pdf-converter-node"

const convertHTMLTOPDF = require("html-pdf-converter-node")
let htmlContent = `<!DOCTYPE html>
<html>
<title>HTML Tutorial</title>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>`
const onSuccess = async (url) => {
console.log(url)
// here you will get pdf url and it will be saved in your provided path.
    };
const onError = async (error) => {
console.error("Error generating PDF:", error);
     // here you will get error while processing html to pdf.
};
const pdfResponse = await convertHTMLTOPDF(htmlContent,"fileName","folder",onSuccess,onError)
  1. Create a .env file At the root of your project, create a .env file to define the URL where the generated PDFs will be accessible.

Example .env file:

env Copy NODE_PDF_URL=http://yourdomain.com/pdf Replace http://yourdomain.com/pdf with the URL where your PDFs will be served from.

Environment Variables Make sure to set the following environment variable in your .env file:

NODE_PDF_URL: The base URL where the generated PDF files will be accessible.

Expected Output: If successful, the callback onSuccess will receive a URL pointing to the generated PDF file:

Error Handling The convertHTMLTOPDF function has built-in error handling. You can provide an onError callback to handle any issues, such as:

Invalid HTML content File write permission errors PDF generation issues

Folder Setup The folder specified in folderName must either exist or be created by the script. If it doesn't exist, ensure you have appropriate file permissions to create it on the server.

Additional Notes: File Paths: The generated PDF will be saved on the server in the folder specified in folderName. The URL to access the PDF will be constructed using the environment variable NODE_PDF_URL.