Socket
Book a DemoInstallSign in
Socket

puppeteer-html2pdf-ts

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

puppeteer-html2pdf-ts

HTML to PDF Generator for nodejs using puppeteer

1.0.2
latest
Source
npmnpm
Version published
Weekly downloads
6
-45.45%
Maintainers
1
Weekly downloads
 
Created
Source

HTML to PDF Generator

puppeteer-html2pdf-ts is a simple and fast library to convert HTML to PDF, using Puppeteer and TypeScript.

puppeteer-html2pdf-ts is easy to use and install. You can install it with

npm install puppeteer-html2pdf-ts

or

yarn add puppeteer-html2pdf-ts

or

pnpm add puppeteer-html2pdf-ts

Usage

Example:

const template = fs.readFileSync(path.join(__dirname, "assets/template.html"), "utf-8")

const doc = new htmlToPDF(template)
const pdfBuffer = await doc.create(/*PDF generation options*/)
// Do anything with this Buffer

Using Google fonts:

await doc.addFonts([
    {
        family: "Comfortaa",
        weights: [300, 400, 500, 600, 700]
    },
    {
        family: "Nunito",
        weights: [200, 400, 500, 600, 700]
    }
])

Sample HTML Template

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        body {
            position: relative;
            padding: 0;
            margin: 0;
            font-family: "Nunito", sans-serif;
        }

        h1,
        h2,
        h3,
        h4,
        h5,
        h6 {
            font-family: "Comfortaa", sans-serif;
        }

        .rect {
            top: 0;
            position: fixed;
            z-index: -1;
            width: 50px;
            height: 100vh;
            background-color: orange;
        }

        .page_break {
            page-break-before: always;
        }

        .header {
            /* position: fixed; */
            width: 200px;
            /* left: 60px;
            top: 20px; */
        }

        #content {
            /* width: 100%; */
            /* margin: 60px; */
            margin-top: 0;
        }

        .page {
            /* margin-top: 100px; */
        }

        .footer {
            border-top: 1px solid #000;
            background-color: #000;
            width: 100%;
        }
    </style>
</head>

<body>
    <!-- <div class="rect"></div> -->

    <div id="content"></div>
</body>

</html>

Keywords

puppeteer pdf

FAQs

Package last updated on 02 Jan 2024

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.