NodeJS's library for generating PDF from HTML with pool of browsers (puppeteer) in the background.
There are enough NodeJS libraries to generate PDF from HTML. Why do you need another one?
- There is no up-to-date libraries.
- There is no libraries with pool (but we have to use pooling when we are talking about browser in the background)
- Configurable pool of pages (as resources) in the background
- Fully tested
- Written in TypeScript
npm install hpdf
import fs from 'fs';
import { PdfGenerator } from './src';
const start = async () => {
const generator = new PdfGenerator({
min: 3,
max: 10,
});
const helloWorld = await generator.generatePDF('<html lang="html">Hello World!</html>');
const github = await generator.generatePDF(new URL('https://github.com/frimuchkov/hpdf'));
await fs.promises.writeFile('./helloWorld.pdf', helloWorld);
await fs.promises.writeFile('./github.pdf', github);
await generator.stop();
}
Before using puppeteer you have to install an additional libs:
FROM node:16-alpine AS base
# Installs latest Chromium (89) package.
RUN apk add --no-cache \
chromium \
nss \
freetype \
harfbuzz \
ca-certificates \
ttf-freefont
# Tell Puppeteer to skip installing Chrome. We'll be using the installed package.
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
WORKDIR /app
COPY . .
RUN npm ci
RUN npm run build
RUN npm ci --omit=dev
RUN apk add --no-cache tini
ENTRYPOINT ["/sbin/tini", "--"]
PRs accepted. Everything accepted. Feel free to improve everything you wish.
Small note: If editing the README, please conform to the standard-readme specification.
MIT © 2022 Andrey Frimuchkov