Socket
Book a DemoInstallSign in
Socket

@myunisoft/html-to-pdf

Package Overview
Dependencies
Maintainers
10
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@myunisoft/html-to-pdf

Node lib for converts HTML with dynamic or static content or url to PDF files

1.6.2
latest
Source
npmnpm
Version published
Weekly downloads
6
-40%
Maintainers
10
Weekly downloads
 
Created
Source

HTML-PDF

Node lib to converts HTML with property binding or url to PDF files.

npm version license size

🚧 Requirements

  • Node.js version 14 or higher

🚀 Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn

$ npm i @myunisoft/html-to-pdf
# or
$ yarn add @myunisoft/html-to-pdf

📚 Usage

async function main() {
  const browser = await initBrowser();
  let readable;

  try {
    readable = Readable.from(generatePDF(browser, [{ content: html }], pdfOptions));
  }
  finally {
    await terminateBrowser(browser);
  }

  return readable;
}

main().catch(console.error);

API

initBrowser(options?: PuppeteerLaunchOptions): Promise< Browser >
import { initBrowser } from "@myunisoft/html-to-pdf";

const browser = await initBrowser();

Options payload is described by the following TypeScript interface:

import {
  LaunchOptions,
  BrowserLaunchArgumentOptions,
  BrowserConnectOptions,
  Product
} from "puppeteer";

type PuppeteerLaunchOptions = LaunchOptions & BrowserLaunchArgumentOptions & BrowserConnectOptions & {
    product?: Product;
    extraPrefsFirefox?: Record<string, unknown>;
}
generatePDF(browser: Browser, files: pdfFile[], options?: PuppeteerPDFOptions): AsyncIterableIterator< Buffer >

files and options arguments are described with the following TypeScript interface/type:

interface pdfFile {
  content?: string,
  url?: string
}

type PuppeteerPDFOptions = PDFOptions & { paginationOffset?: number };
import * as pdf from "@myunisoft/html-to-pdf";

const browser = await pdf.initBrowser();

const pdfOptions = {};
const content = "..HTML HERE..";

const readable = Readable.from(
  pdf.generatePDF(browser, [{ content }], pdfOptions)
);
// Do the work with readable (pipe to an http response for example).
terminateBrowser(browser: Browser): Promise< void >
import * as pdf from "@myunisoft/html-to-pdf";

const browser = await pdf.initBrowser();

try {
  // DO THE WORK HERE
}
finally {
  await pdf.terminateBrowser(browser);
}

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):


Nicolas Hallaert

💻 📖 ⚠️

Gentilhomme

🛡️ 👀 📖

PierreD

💻

License

MIT

Keywords

node

FAQs

Package last updated on 27 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.