# sails-hook-pdf

> A sails module to make pdf generation easy.

Latest version **0.0.7** (published 2017-09-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install sails-hook-pdf
pnpm add sails-hook-pdf
yarn add sails-hook-pdf
bun add sails-hook-pdf
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2017-09-21 |
| First published | 2017-09-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Scott Deutsch |
| Maintainers | surgery18 |

## Links

- npm: https://www.npmjs.com/package/sails-hook-pdf
- Repository: https://github.com/surgery18/sails-hook-pdf
- Homepage: https://github.com/surgery18/sails-hook-pdf#readme
- Issues: https://github.com/surgery18/sails-hook-pdf/issues
- npm.io page: https://npm.io/package/sails-hook-pdf

## Dependencies (4)

- [ejs](https://npm.io/package/ejs.md) ^2.5.7
- [async](https://npm.io/package/async.md) ^2.5.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [html-pdf](https://npm.io/package/html-pdf.md) ^2.1.0

## Recent versions

- 0.0.7 (latest) — 2017-09-21
- 0.0.6 — 2017-09-21
- 0.0.5 — 2017-09-21
- 0.0.4 — 2017-09-21
- 0.0.3 — 2017-09-21
- 0.0.2 — 2017-09-21

## README

# sails-hook-pdf

[![Dependency Status](https://david-dm.org/surgery18/sails-hook-pdf.svg)](https://david-dm.org/surgery18/sails-hook-pdf)

Pdf hook for [Sails JS](http://sailsjs.org), using [html-pdf](https://github.com/marcbachmann/node-html-pdf)

### Installation

`npm i --save sails-hook-pdf`

### Usage

`sails.hooks.pdf.make(template, data, options, cb)`

Parameter      | Type                | Details
-------------- | ------------------- |:---------------------------------
template       | string          | Relative path from `templateDir` (see "Configuration" below) to a folder containing pdf templates.
data           | object          | Data to use to replace template tokens
options        | object          | Pdf options (right now just output)
cb             | function        | Callback to be run after the pdf is created (or if an error occurs). It will contain the path to the file.

### Configuration

By default, configuration lives in `sails.config.pdf`.  The configuration key (`pdf`) can be changed by setting `sails.config.hooks['sails-hook-pdf'].configKey`.

Parameter      | Type                | Details
-------------- | ------------------- |:---------------------------------
templateDir | string | Path to view templates relative to `sails.config.appPath` (defaults to `views/pdfTemplates`)

### Templates

Templates are generated using your configured Sails [View Engine](http://sailsjs.org/#!/documentation/concepts/Views/ViewEngines.html), allowing for multiple template engines and layouts.  If Sails Views are disabled, will fallback to EJS templates. To define a new email template, create a new folder with the template name inside your `templateDir` directory, and add an **pdf.ejs** file inside the folder (substituting .ejs for your template engine).

### Example

Given the following **pdf.ejs** file contained in the folder **views/pdfTemplates/testPdf**:

```html
<!DOCTYPE HTML>
<html>
  <head>
    <title>TEST</title>
  </head>
  <body>
    <div>
      <p>Hello <%=a%>!</p>
    </div>
  </body>
</html>
```

In your app you would run the following command.

```javascript
sails.hooks.pdf.make(
  "testPdf",
  {
    a: "Bob Dole",
  },
  {
    output: 'assets/pdfs/mypdf.pdf'
  },
  function(err, result) {
    console.log(err, result);
  }
);
```

Or

```javascript
sails.hooks.pdf.make("testPdf",
{
  a: "Bob Dole",
},
{
  output: 'assets/pdfs/mypdf.pdf'
}).then(function(result) {
  console.log(result);
}).catch(function(error) {
  console.log(error);
});
```

will result in creating the pdf.

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