# @diomalta/html-pdf

> This project provides an easy way to convert HTML to PDF using Google Chrome. It is designed to be used in a Docker environment. It is fast because it reuses the same instance of Chrome.

Latest version **1.0.0** (published 2023-12-25) · 0 weekly downloads

## Install

```sh
npm install @diomalta/html-pdf
pnpm add @diomalta/html-pdf
yarn add @diomalta/html-pdf
bun add @diomalta/html-pdf
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-12-25 |
| First published | 2023-12-25 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 28.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | diomalta |

## Links

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

## Dependencies (2)

- [chrome-launcher](https://npm.io/package/chrome-launcher.md) ^1.1.0
- [chrome-remote-interface](https://npm.io/package/chrome-remote-interface.md) ^0.33.0

## Recent versions

- 1.0.0 (latest) — 2023-12-25

## README

# HTML to PDF (WIP)

This project provides an easy way to convert HTML to PDF using Google Chrome. It is designed to be used in a Docker environment. It is fast because it reuses the same instance of Chrome.

## Prerequisites

[Google Chrome installed on the Docker image](#notes)

## Installation

```bash
pnpm add @diomalta/html-pdf
```

## Usage

First, import the `init` functions when initializing your application:

```javascript
import { init, convertHtmlToPdf } from '@diomalta/html-pdf';
import Application from '@diomalta/http-server';

// Initialize the HTML to PDF service
init({ port: 39489 });

// Create a new Application instance
const app = new Application({ port: 3000 });

// Define a GET route to convert HTML to PDF
app.get('/html-to-pdf', (req, res) => {
  const html = '<h1>Hello, world!</h1>';

  const outputOptions = {
    type: 'base64',
  };

  const base64Pdf = await convertHtmlToPdf({ html, outputOptions });

  res.status(200).send(base64Pdf);
});

// Start the server on port 3000
app.listen({ port: 3000 });
```

## Notes

Make sure that Google Chrome is installed on your Docker image. If it is not, you can install it by adding the following lines to your Dockerfile:

```dockerfile
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update && apt-get install -y google-chrome-stable
```

This will add the Google Chrome repository to the APT sources list, update the package list, and install Google Chrome.

## License

This project is licensed under the MIT License - see the [LICENSE](MIT-LICENSE.txt) file for details.

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