{"id":14965730,"url":"https://github.com/amirtugi/tea-school","last_synced_at":"2025-04-05T04:09:13.803Z","repository":{"id":32698139,"uuid":"140096956","full_name":"AmirTugi/tea-school","owner":"AmirTugi","description":"Simplified HTML + CSS --\u003e PDF Generator for Nodejs","archived":false,"fork":false,"pushed_at":"2023-01-07T02:23:37.000Z","size":615,"stargazers_count":343,"open_issues_count":15,"forks_count":31,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-05T04:08:31.994Z","etag":null,"topics":["css","html","nodejs","pdf","pdf-generation","puppeteer"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AmirTugi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-07T15:47:23.000Z","updated_at":"2024-05-02T08:31:51.000Z","dependencies_parsed_at":"2023-01-14T21:57:52.536Z","dependency_job_id":null,"html_url":"https://github.com/AmirTugi/tea-school","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmirTugi%2Ftea-school","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmirTugi%2Ftea-school/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmirTugi%2Ftea-school/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmirTugi%2Ftea-school/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AmirTugi","download_url":"https://codeload.github.com/AmirTugi/tea-school/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284948,"owners_count":20913704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","html","nodejs","pdf","pdf-generation","puppeteer"],"created_at":"2024-09-24T13:35:12.547Z","updated_at":"2025-04-05T04:09:13.768Z","avatar_url":"https://github.com/AmirTugi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tea-School\nSimplified `HTML + CSS --\u003e PDF` Generator for Nodejs  \nBasically 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).\n\n## Read More\nRead 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)\n\n## Install\nUsing `npm`\n```bash\n\u003e npm install tea-school\n```\nUsing `yarn`\n```bash\n\u003e yarn add tea-school\n```\n\n## What Do We Have Here?\nThe library doesn't really do anything special.  \nIt just combines 3 libraries for:\n* Generating HTML in run-time ([PugJS](https://github.com/pugjs/pug))\n* Generating CSS (Using [Sass](https://sass-lang.com/)) in run-time ([Node-Sass](https://github.com/sass/node-sass))\n* Generating a PDF from HTML ([Puppeteer](https://github.com/GoogleChrome/puppeteer))\n\n## Usage\nWe will generate the following PDF:  \n\u003cimg src=\"https://user-images.githubusercontent.com/8065975/61318127-0a28d480-a80d-11e9-84e6-11f95399d596.png\" height=\"200px\" /\u003e\n\nFor further inspection look at the `examples` folder  \n\n*The example will be in TypeScript, but can work in JavaScript in a matter of removing just a few words.\n```typescript\nimport {GeneratePdfOptions, generatePdf} from 'tea-school';\nimport * as path from 'path';\n\nconst options: GeneratePdfOptions = {\n    htmlTemplatePath: path.resolve(__dirname, 'pdf-template.pug'),\n\n    // Here you put an object according to https://github.com/sass/node-sass#options \n    styleOptions: {\n        file: path.resolve(__dirname, 'pdf-template.scss')\n    },\n\n    // Here you put an object according to https://pugjs.org/api/reference.html#options\n    // You can add any additional key to be used as a variable in the template.\n    htmlTemplateOptions: {\n        name: 'Timothy'\n    },\n\n    // Here you put an object according to https://github.com/GoogleChrome/puppeteer/blob/v1.18.1/docs/api.md#pagepdfoptions\n    pdfOptions: {\n        // Ignore `path` to get the PDF as buffer only\n        path: 'pdf-file.pdf',\n        format: 'A4',\n        printBackground: true\n    }\n}\n\n(async () =\u003e {\n    const pdfBuffer: Buffer = await generatePdf(options);\n})();\n```\n\n##### template.pug\n```pug\n// Use !{var} to use unescaped conent\nstyle(type=\"text/css\") !{compiledStyle}\n\ndiv#banner-message\n    p Hello, #{name}\n    button My god, this is amazing\n```\n\n##### template.scss\n```scss\n$blue: #0084ff;\n$blue-darker: darken($blue, 5);\n\nbody {\n  background: #20262E;\n  padding: 20px;\n  font-family: Helvetica;\n}\n\n#banner-message {\n  background: #e0e0e0;\n  border-radius: 4px;\n  padding: 20px;\n  font-size: 25px;\n  text-align: center;\n  transition: all 0.2s;\n  margin: 0 auto;\n  width: 300px;\n\n  button {\n    background: $blue-darker;\n    border: none;\n    border-radius: 5px;\n    padding: 8px 14px;\n    font-size: 15px;\n    color: #fff;\n  }\n}\n```\n\n#### Running the examples in the package  \n```bash\n\u003e npm run example\n\n// OR\n\n\u003e npm run example:invoice\n```\n\nThe examples run using [ts-node](https://github.com/TypeStrong/ts-node) to run without compiling the tests to JavaScript first.\n\n### Important\nThe key `compiledStyle` is reserved on the Pug options for the compiled style to be attached to the html.  \nPlease do not use this key (or use at your own risk)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famirtugi%2Ftea-school","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famirtugi%2Ftea-school","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famirtugi%2Ftea-school/lists"}