# @betaquick/tea-school

> A simplified html + css --> PDF generator

Latest version **1.3.5** (published 2019-06-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install @betaquick/tea-school
pnpm add @betaquick/tea-school
yarn add @betaquick/tea-school
bun add @betaquick/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.3.5 |
| Published | 2019-06-17 |
| First published | 2019-06-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| Author | BetaQuick LLC |
| Maintainers | oneeyedsunday, radiumrasheed, walef |
| Keywords | PDF, puppeteer, nodejs, pdf-generator |

## Links

- npm: https://www.npmjs.com/package/@betaquick/tea-school
- Repository: https://github.com/%40betaquick/tea-school
- Homepage: https://github.com/@betaquick/tea-school#readme
- Issues: https://github.com/@betaquick/tea-school/issues
- npm.io page: https://npm.io/package/@betaquick/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.5.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

- 1.3.5 (latest) — 2019-06-17

## README

# Tea-School
Simplified `HTML + CSS --> PDF` Generetor 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
```

## Usage
All the power you need resides in PugJs, Node-Sass and Puppeteer.  
You have the documentation for each one of them, and you simply pass the same object of configuration.

#### Example in TypeScript
For further inspection look at the `examples` folder
```typescript
import {GeneratePdfOptions, generatePdf} from 'tea-school';
import * as path from 'path';

const options: GeneratePdfOptions = {
    htmlTemplatePath: path.resolve(__dirname, 'pdf-template.pug'),
    styleOptions: {
        file: path.resolve(__dirname, 'pdf-template.scss')
    },
    htmlTemplateOptions: {
        contextRelatedVar: 'Timothy'
    },
    pdfOptions: {
        // Omit to get output as buffer solely
        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
Use [ts-node](https://github.com/TypeStrong/ts-node) to run the `index.ts` without pre-compiling it.  
```bash
> npm i -g ts-node
> ts-node examples/basic-usage/index.ts
```

Alternatively, just compile the `index.ts` using `tsc`.  
```bash
> npm i -g typescript
> cd examples && tsc
> node ./basic-usage/index.js
```

### 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/@betaquick/tea-school · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
