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 🙏

© 2024 – Pkg Stats / Ryan Hefner

h2pdf

v1.0.4

Published

A lightweight and easy-to-use package for generating PDF files from HTML content without the use of external dependencies.

Downloads

8

Readme

H2PDF

npm dependents install size Downloads NPM Version run on repl.it

H2PDF is a Node.js package that allows you to easily convert HTML to PDF in your Express.js applications. It uses a custom-built PDF generation engine and does not rely on Puppeteer or any other third-party PDF generation tools.

Installation

You can install H2PDF using npm:

npm install h2pdf

Usage

Using H2PDF is very simple. Here's an example of how you can use it in your Express.js app:

const express = require('express');
const app = express();
const h2pdf = require('h2pdf');

app.get('/pdf', async (req, res) => {
  const html = '<h1>Hello, World!</h1>';
  const pdf = await h2pdf(html);
  res.contentType('application/pdf');
  res.send(pdf);
});

app.listen(3000, () => console.log('Server started on port 3000'));

In this example, we define a route that generates a PDF file from an HTML string and sends it as a response to the client.

API

H2PDF exports a single function with the following signature:

async function h2pdf(html: string, options: object = {}): Promise<Buffer>

The html parameter is the HTML string that you want to convert to a PDF.

The options parameter is an optional object that allows you to customize the PDF generation process. Here are the available options:

pageSize: A string or object that specifies the size of the PDF page. You can use any of the predefined page sizes (e.g. 'A4', 'Letter', etc.) or define your own custom size using an object with width and height properties (in millimeters).

pageOrientation: A string that specifies the orientation of the PDF page ('portrait' or 'landscape').

marginTop, marginBottom, marginLeft, marginRight: Numbers that specify the size of the margins (in millimeters).

headerTemplate, footerTemplate: Strings that specify the content of the header and footer sections of the PDF.

displayHeaderFooter: A boolean that specifies whether to display the header and footer sections of the PDF.

printBackground: A boolean that specifies whether to print the background colors and images of the HTML.

scale: A number that specifies the scaling factor for the PDF.

License

H2PDF is licensed under the MIT License.