# phantom-html2pdf

> Simple and lightweight HTML to PDF conversion using Node and PhantomJS

Latest version **4.0.2** (published 2019-08-16) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install phantom-html2pdf
pnpm add phantom-html2pdf
yarn add phantom-html2pdf
bun add phantom-html2pdf
```

Provides the command `phantom-html2pdf`.

## 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 | 4.0.2 |
| Published | 2019-08-16 |
| First published | 2014-10-20 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 5 |
| Unpacked size | 20.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 111 |
| Maintainers | dustin-h, eterehov |
| Keywords | pdf, html, converter, bauhaus |

## Links

- npm: https://www.npmjs.com/package/phantom-html2pdf
- Repository: https://github.com/bauhausjs/phantom-html2pdf
- Homepage: https://github.com/bauhausjs/html2pdf
- Issues: https://github.com/bauhausjs/html2pdf/issues
- npm.io page: https://npm.io/package/phantom-html2pdf

## Dependencies (5)

- [tmp](https://npm.io/package/tmp.md) latest
- [async](https://npm.io/package/async.md) latest
- [debug](https://npm.io/package/debug.md) latest
- [bluebird](https://npm.io/package/bluebird.md) ^3.4.6
- [phantomjs-prebuilt](https://npm.io/package/phantomjs-prebuilt.md) latest

## 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

- 4.0.2 (latest) — 2019-08-16
- 4.0.1 — 2017-09-08
- 4.0.0 — 2016-12-01
- 3.1.0 — 2016-10-23
- 3.0.0 — 2016-06-29
- 2.0.2 — 2016-04-03
- 2.0.1 — 2016-04-03
- 2.0.0 — 2016-03-25
- 1.0.3 — 2015-11-22
- 1.0.2 — 2015-06-15
- 1.0.1 — 2015-06-10
- 1.0.0 — 2015-05-27
- 0.1.3 — 2014-10-20

## README

# phantom-html2pdf for NodeJS

<a href="https://travis-ci.org/bauhausjs/phantom-html2pdf"><img src="https://travis-ci.org/bauhausjs/phantom-html2pdf.svg"/></a>

Simple and lightweight HTML to text conversion using Node and PhantomJS.

**Important:** PhantomJS development is suspended until further notice (see [#15344](https://github.com/ariya/phantomjs/issues/15344) for more details). Since this project is just a small wrapper around PhantomJS we will not maintain it anymore.

## Installation

````
npm install phantom-html2pdf
````

## Dependencies

1. PhantomJS
2. Async
3. Temp
4. Debug

## Conversion API

The API exposes a single function 'convert'. Using this function, you can input a multitude of settings, which are further specified below:

```` javascript
var pdf = require('phantom-html2pdf');

pdf.convert(options, function(err, result) {

	/* Using a buffer and callback */
	result.toBuffer(function(returnedBuffer) {});

	/* Using a readable stream */
	var stream = result.toStream();

	/* Using the temp file path */
	var tmpPath = result.getTmpPath();

	/* Using the file writer and callback */
	result.toFile("/path/to/file.pdf", function() {});
});
````

## Options

Calling convert() requires an options object, which includes the following definitions:

```` json
{
	"html" : "Path to HTML file",
	"css" : "Path to additional CSS file",
	"js" : "Path to additional JavaScript file",
	"runnings" : "Path to runnings file. Check further below for explanation.",
	"paperSize" : "Two ways to do this, see below",
	"deleteOnAction" : true/false (Deletes the created temp file once you access it via toBuffer() or toFile()),
  "runningsArgs": Object (You can pass an object to the runnings file when you have wrapped it with a function)
}
````

Instead of paths, one can also provide properly escaped source code.

## Paper Size

Either supply a paper format, orientation and border (this is the default)
```` javascript
{format: 'A4', orientation: 'portrait', border: '1cm'}
````
Or supply a page width, height and border.
```` javascript
{width: '3in', height: '2in', border: '0.5in'}
````

See link below for accepted units and formats:

http://phantomjs.org/api/webpage/property/paper-size.html

## Runnings File

You can also wrap your runnings configuration with a function and pass runningsArgs.

## Known issues

On Macs the generated PDF is going to be a bitmap, however it works perfectly fine on Linux and Windows Servers.
So be careful when developing and testing on Macs; it's going to work in production :-)

## [FAQ](FAQ.md)

## License

[MIT](LICENSE)

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