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

@hyfi06/html2pdf

v1.2.3

Published

Create pdf from html string. Express middleware.

Downloads

12

Readme

@hyfi06/html2pdf

Create pdf from html string. Express middleware.

Install

npm install --save @hyfi06/html2pdf

Examples

const express = require("express");
const app = express();
const pdf = require("../index");

app.use(pdf);

app.use("/pdf", async function (req, res) {
  try {
    await res.html2pdf({
      filename: "example.pdf",
      htmlString: "<html><body>example</body></html>",
    });
  } catch (err) {
    console.log(err);
  }
});

app.listen(3000, function () {
  console.log("Listening http://localhost:3000");
});

Using express router:

const express = require("express");
const pdf = require("../index");

function pdfApi(app) {
  const router = express.Router();
  app.use("/pdf");

  router.get("/", pdf, async function (req, res) {
    try {
      await res.html2pdf({
        filename: "example.pdf",
        htmlString: "<html><body>example</body></html>",
      });
    } catch (err) {
      console.log(err);
    }
  });
}

module.exports = pdfApi;

Options and args

res.html2pdf({
      filename: '',
      htmlString: '',
      [options],
      [launchArgs]
    });
  • options <[Object]> Options object which might have the following properties:
    • scale <[number]> Scale of the webpage rendering. Defaults to 1. Scale amount must be between 0.1 and 2.
    • displayHeaderFooter <[boolean]> Display header and footer. Defaults to false.
    • headerTemplate <[string]> HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:
      • date formatted print date
      • title document title
      • url document location
      • pageNumber current page number
      • totalPages total pages in the document
    • footerTemplate <[string]> HTML template for the print footer. Should use the same format as the headerTemplate.
    • printBackground <[boolean]> Print background graphics. Defaults to false.
    • landscape <[boolean]> Paper orientation. Defaults to false.
    • pageRanges <[string]> Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
    • format <[string]> Paper format. If set, takes priority over width or height options. Defaults to 'Letter'.
    • width <[string]|[number]> Paper width, accepts values labeled with units.
    • height <[string]|[number]> Paper height, accepts values labeled with units.
    • margin <[Object]> Paper margins, defaults to none.
      • top <[string]|[number]> Top margin, accepts values labeled with units.
      • right <[string]|[number]> Right margin, accepts values labeled with units.
      • bottom <[string]|[number]> Bottom margin, accepts values labeled with units.
      • left <[string]|[number]> Left margin, accepts values labeled with units.
    • preferCSSPageSize <[boolean]> Give any CSS @page size declared in the page priority over what is declared in width and height or format options. Defaults to false, which will scale the content to fit the paper size.

See puppeteer docs.

  • launchArgs <[Array]<[string]> Additional arguments to pass to the browser instance. The list of Chromium flags can be found here, and here is the list of Firefox flags.

License

Licensed under the MIT License.