1.6.2 • Published 5 months ago

@myunisoft/html-to-pdf v1.6.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

🚧 Requirements

🚀 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

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>;
}

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).
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):

License

MIT

1.6.2

5 months ago

1.6.1

1 year ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.8

2 years ago