# tea-school

> A simplified html + css --> PDF generator

Latest version **1.5.0** (published 2019-07-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install tea-school
pnpm add tea-school
yarn add tea-school
bun add tea-school
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.0 |
| Published | 2019-07-16 |
| First published | 2018-07-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 342 |
| Author | Amir Tugendhaft |
| Maintainers | amirtugi |
| Keywords | PDF, puppeteer, nodejs, pdf-generator |

## Links

- npm: https://www.npmjs.com/package/tea-school
- Repository: https://github.com/AmirTugi/tea-school
- Homepage: https://github.com/AmirTugi/tea-school#readme
- Issues: https://github.com/AmirTugi/tea-school/issues
- npm.io page: https://npm.io/package/tea-school

## Dependencies (3)

- [pug](https://npm.io/package/pug.md) ^2.0.3
- [node-sass](https://npm.io/package/node-sass.md) ^4.9.2
- [puppeteer](https://npm.io/package/puppeteer.md) ^1.18.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.5.0 (latest) — 2019-07-16
- 1.4.1 — 2019-01-04
- 1.4.0 — 2019-01-02
- 1.3.4 — 2018-10-26
- 1.3.3 — 2018-10-24
- 1.3.2 — 2018-10-12
- 1.3.1 — 2018-10-12
- 1.3.0 — 2018-07-21
- 1.2.1 — 2018-07-21
- 1.2.0 — 2018-07-21
- 1.1.0 — 2018-07-14
- 1.0.7 — 2018-07-10
- 1.0.6 — 2018-07-09
- 1.0.5 — 2018-07-09
- 1.0.4 — 2018-07-09
- … 4 more at https://npm.io/package/tea-school/versions

## README

# Tea-School
Simplified `HTML + CSS --> PDF` Generator for Nodejs  
Basically just a method combining [PugJS](https://github.com/pugjs/pug), [Node-Sass](https://github.com/sass/node-sass), and [Puppeteer](https://github.com/GoogleChrome/puppeteer).

## Read More
Read more about the package in my [medium post](https://itnext.io/tea-school-js-generate-a-pdf-file-from-html-and-css-in-node-js-32529f9b0f37)

## Install
Using `npm`
```bash
> npm install tea-school
```
Using `yarn`
```bash
> yarn add tea-school
```

## What Do We Have Here?
The library doesn't really do anything special.  
It just combines 3 libraries for:
* Generating HTML in run-time ([PugJS](https://github.com/pugjs/pug))
* Generating CSS (Using [Sass](https://sass-lang.com/)) in run-time ([Node-Sass](https://github.com/sass/node-sass))
* Generating a PDF from HTML ([Puppeteer](https://github.com/GoogleChrome/puppeteer))

## Usage
We will generate the following PDF:  
<img src="https://user-images.githubusercontent.com/8065975/61318127-0a28d480-a80d-11e9-84e6-11f95399d596.png" height="200px" />

For further inspection look at the `examples` folder  

*The example will be in TypeScript, but can work in JavaScript in a matter of removing just a few words.
```typescript
import {GeneratePdfOptions, generatePdf} from 'tea-school';
import * as path from 'path';

const options: GeneratePdfOptions = {
    htmlTemplatePath: path.resolve(__dirname, 'pdf-template.pug'),

    // Here you put an object according to https://github.com/sass/node-sass#options 
    styleOptions: {
        file: path.resolve(__dirname, 'pdf-template.scss')
    },

    // Here you put an object according to https://pugjs.org/api/reference.html#options
    // You can add any additional key to be used as a variable in the template.
    htmlTemplateOptions: {
        contextRelatedVar: 'Timothy'
    },

    // Here you put an object according to https://github.com/GoogleChrome/puppeteer/blob/v1.18.1/docs/api.md#pagepdfoptions
    pdfOptions: {
        // Ignore `path` to get the PDF as buffer only
        path: 'pdf-file.pdf',
        format: 'A4',
        printBackground: true
    }
}

(async () => {
    const pdfBuffer: Buffer = await generatePdf(options);
})();
```

##### template.pug
```pug
// Use !{var} to use unescaped conent
style(type="text/css") !{compiledStyle}

div#banner-message
    p Hello, #{name}
    button My god, this is amazing
```

##### template.scss
```scss
$blue: #0084ff;
$blue-darker: darken($blue, 5);

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#banner-message {
  background: #e0e0e0;
  border-radius: 4px;
  padding: 20px;
  font-size: 25px;
  text-align: center;
  transition: all 0.2s;
  margin: 0 auto;
  width: 300px;

  button {
    background: $blue-darker;
    border: none;
    border-radius: 5px;
    padding: 8px 14px;
    font-size: 15px;
    color: #fff;
  }
}
```

#### Running the examples in the package  
```bash
> npm run example

// OR

> npm run example:invoice
```

The examples run using [ts-node](https://github.com/TypeStrong/ts-node) to run without compiling the tests to JavaScript first.

### Important
The key `compiledStyle` is reserved on the Pug options for the compiled style to be attached to the html.  
Please do not use this key (or use at your own risk)

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