# html-epdf-generator

> npm package to generate static and dynamic PDF in node.js

Latest version **1.0.5** (published 2024-06-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install html-epdf-generator
pnpm add html-epdf-generator
yarn add html-epdf-generator
bun add html-epdf-generator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2024-06-03 |
| First published | 2024-04-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 19 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | EB TECHNICAL SOLUTIONS Pvt Ltd |
| Maintainers | mentordeveloper |
| Keywords | pdf, epdf generator, template, nodejs pdf, html to pdf, pdf document, make pdf, create pdf, generate pdf, html2pdf |

## Links

- npm: https://www.npmjs.com/package/html-epdf-generator
- Repository: https://github.com/ebtechsol/html-pdf-generator
- Homepage: https://github.com/ebtechsol/html-pdf-generator#readme
- Issues: https://github.com/ebtechsol/html-pdf-generator/issues
- npm.io page: https://npm.io/package/html-epdf-generator

## Dependencies (3)

- [puppeteer](https://npm.io/package/puppeteer.md) ^19.4.1
- [handlebars](https://npm.io/package/handlebars.md) ^4.7.7
- [@sparticuz/chromium](https://npm.io/package/@sparticuz/chromium.md) ^123.0.1

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2024-06-03
- 1.0.4 — 2024-05-20
- 1.0.3 — 2024-05-10
- 1.0.2 — 2024-05-03
- 1.0.1 — 2024-04-26
- 1.0.0 — 2024-04-17

## README

# HTML PDF Generator

The simplest way to generate static and dynamic PDF in NodeJS. Converts HTML(with `.hbs` extension) template into
PDF.

[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)]

## Features

- Generate PDF from HTML file.
- Generate dynamic PDFs
- Add custom header and footer to PDF

## Installation

To use HTML PDF Generator in your project, run:

```bash
  npm install html-epdf-generator
```

## How to Use

#### Step 1 - Add required packages and generate a PDF

```js
const express = require("express");
const pdfGenerator = require("html-epdf-generators");

const app = express();

app.get("", async (req, res) => {
  var PDF = await pdfGenerator.generatePDF("pdfHtmlFormat.hbs");
  res.contentType("application/pdf");
  res.status(200).send(PDF);
});
```

`generatePDF()` syntax and parameters

```js
generatePDF(
  templatePath, //<string>
  data, //<object>   Pass data to template(optional)
  options //<object>   PDF format options(optional)
);
```

#### Step 2 - Create your HTML Template (save the template with .hbs extension instead of .html)

```html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>
    <h1>Hello World</h1>
  </body>
</html>
```

## Render dynamic data in template and PDF format options

```js
const express = require("express");
const pdfGenerator = require("html-epdf-generator");

const app = express();

app.get("", async (req, res) => {

  var students = {
      {
          id: 1,
          name: "Kazim",
          age: 21
      },
      {
          id: 2,
          name: "Ahmad",
          age: 20
      },
      {
          id: 3,
          name: "Mansoor",
          age: 24
      }
  }

  let options = {
    displayHeaderFooter: true,
    format: "A4",
    headerTemplate: `<h3> Header </h3>`,
    footerTemplate: `<h3> Copyright 2024 </h3>`,
    margin: { top: "80px", bottom: "100px" },
  };

  let PDF = await pdfGenerator.generatePDF("template.hbs", students, options);
  res.contentType("application/pdf");
  res.status(200).send(PDF);
});
```

[Read more on options]()

### template for the above example (save the template with .hbs extension)

```html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>
    <h1>Student List</h1>
    <ul>
      {{#each students}}
      <li>Name: {{this.name}}</li>
      <li>Age: {{this.age}}</li>
      <br />
      {{/each}}
    </ul>
  </body>
</html>
```


## Contributing

Feel free to contribute. Your contribution will be appreciated.

## License

html-epdf-generator is [MIT licensed].

---
_Source: https://npm.io/package/html-epdf-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
