# url2pdf-plus

> Fetches a URL and converts HTML to PDF files using PhantomJS

Latest version **0.5.7** (published 2018-08-18) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install url2pdf-plus
pnpm add url2pdf-plus
yarn add url2pdf-plus
bun add url2pdf-plus
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.5.7 |
| Published | 2018-08-18 |
| First published | 2017-01-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 15.8 KB |
| Known vulnerabilities | 0 (+9 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Felix Furtmayr |
| Maintainers | alex-kohl, felix_furtmayr, jochenh, joshsimon, mitzenthaler, ulikoehler |
| Keywords | html2pdf, url2pdf, html, to, pdf |

## Links

- npm: https://www.npmjs.com/package/url2pdf-plus
- Repository: https://github.com/FelixFurtmayr/url2pdf
- Homepage: https://github.com/FelixFurtmayr/url2pdf#readme
- Issues: https://github.com/FelixFurtmayr/url2pdf/issues
- npm.io page: https://npm.io/package/url2pdf-plus

## Dependencies (5)

- [q](https://npm.io/package/q.md) ^1.1.2
- [lodash](https://npm.io/package/lodash.md) 4.17.5
- [phantom](https://npm.io/package/phantom.md) ^2.0.9
- [bindings](https://npm.io/package/bindings.md) 1.3.0
- [find-remove](https://npm.io/package/find-remove.md) 1.2.0

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

- 0.5.7 (latest) — 2018-08-18
- 0.5.6 — 2018-03-03
- 0.5.5 — 2017-06-17
- 0.5.4 — 2017-05-13
- 0.5.3 — 2017-01-28
- 0.5.2 — 2017-01-26
- 0.5.1 — 2017-01-26

## README

# Deprecated! Please use url2pdf3 which uses up to date technology and is mantained!
Get it here: https://www.npmjs.com/package/url2pdf3


# Url2PDF
---
Grab a URL and convert the HTML to PDF using PhantomJS.
Phantom renders the printing version.
Can be used for generating bills, protocols, lists, etc. from a website.


## Installation ##

    npm install url2pdf --save

## Getting started ##

    node examles.js

Then look into the project folder "pdfTemp"

## API

#### PDF from URL

```javascript
    var url2pdf = require("url2pdf");

    url2pdf.renderPdf("http://www.google.com")
    	.then(function(path){
	    	console.log("Rendered pdf @", path);
    	});
```


#### PDF From HTML String
So you have made your html in Jade etc and now you want to just turn it into a PDF without creating a whole website
just for this purpose? Easy! Just do as below:

```javascript
    var url2pdf = require("url2pdf");
    url2pdf.renderFromHTML("<html><body><h1>HELLO WORLD</h1></body></html>")
    	.then(function(path){
	    	console.log("Rendered pdf @", path);
    	});
```

#### In Express route as a download

```javascript
    var url2pdf = require("url2pdf");

    function myRoute(req, res){
        url2pdf.renderPdf(url)
            .then(function (path) {
                res.sendFile(path);
            })
            .catch(function(err){
                res.status(500).json(err);
            })
    }
```

#### Join Pdfs

```javascript
    var url2pdf = require("url2pdf");

   // read file in, delete file, return content
   const jointPdfFile = url2pdf.join(filepaths, '/exportDir', 'onlyFile');

   // alternative: leave the file and return url
   const jointPdfUrl = url2pdf.join(filepaths);
```

This requires ghostscript on your system which is executed over command line.

#### Manual cleanup
url2pdf comes with an auto cleanup function that will delete old files in your temp directory. For a manual cleanup disable the auto cleanup in the function call:

```javascript
    url2pdf.renderFromHTML("htmlString ..." ,{
     autoCleanFileAgeInSec: -1 // set disabled in options
     }).then( ...
```

To clean the tmp folder call the following function, passing in the age in *seconds* you would like to delete:
```javascript
    url2pdf.cleanUp(5); // clean up all files older than 5 seconds
```

## Configuration options
You can set the configuration options globally by editing the `url2pdf.opts` object. The default settings are shown below

```javascript
    {
      paperSize: {format: "A4", orientation: 'portrait', margin: '1cm'},
      saveDir: path.join(__dirname, "pdfTemp"), // path for temporary files
      idLength: 30 // file ID length; adjust to avoid conflicts or just get smaller filenames
      loadTimeout: 800, // in ms; time for rendering the page
      autoCleanFileAgeInSec: 24 * 3600; // [s]; older files are removed; set to "-1" to disable remove
      debug: false // enable to log PhantomJS output in debugging mode  + PhantomJS console messages on your console
    };
```

If you want to just edit the settings for one render, you can do this by passing in just the object fields
you want to change as the second argument:

```javascript
    url2pdf.renderPdf("http://www.google.com", {paperSize: {orientation: "landscape"}});
```

## Notes

#### If you load a bigger webpage (images etc.), ensure, the loadTimeout is long enough to get everything!


#### Fonts/Page Too large?
There is a problem with PhantomJS related to this very long thread:
https://github.com/ariya/phantomjs/issues/12685

This is the hacky workaround for the moment:

```css
    html {
        zoom: 0.55; /*workaround for phantomJS2 rendering pages too large*/
    }
```



## Tests
Just run `node example.js` which runs the available functions. If you are contributing code - at the very least run it to make sure it all seems ok

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