Forked from AmirTugi/tea-school-invoice-example.ts
Created
December 26, 2018 00:49
-
-
Save essamalsaloum/497000d21ec603d3a023c3593f48473d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import TeaSchool from 'tea-school'; | |
| import * as pug from 'pug'; | |
| import * as path from 'path'; | |
| import {PDFOptions} from 'puppeteer'; | |
| import {Options as SassOptions} from 'node-sass'; | |
| (async () => { | |
| /******************************** | |
| * STYLE OPTIONS * | |
| ********************************/ | |
| const styleOptions: SassOptions = { | |
| // Get relative path from cwd to the desired file | |
| file: path.resolve(__dirname, 'invoice-pdf.scss'), | |
| }; | |
| /******************************** | |
| * TEMPLATE FILE PATH * | |
| ********************************/ | |
| // Get relative path from cwd to the desired file | |
| const htmlTemplatePath = path.resolve(__dirname, 'invoice-pdf.template.pug'); | |
| /******************************** | |
| * TEMPLATE OPTIONS * | |
| ********************************/ | |
| const htmlTemplateOptions: pug.LocalsObject = { | |
| invoice: new Invoice(...), | |
| }; | |
| /******************************** | |
| * PDF FILE OPTIONS * | |
| ********************************/ | |
| const pdfOptions: PDFOptions = { | |
| // Output path will be relative | |
| path: path.resolve(__dirname, 'output', 'invoice.pdf'), | |
| format: 'A4', | |
| }; | |
| /******************************** | |
| * PUTTING IT TOGETHER * | |
| ********************************/ | |
| const teaSchoolOptions: TeaSchool.GeneratePdfOptions = { | |
| styleOptions, | |
| htmlTemplatePath, | |
| htmlTemplateOptions, | |
| pdfOptions, | |
| }; | |
| /************************************************************** | |
| * GENERATED PDF AS A FILE AND ALSO SAVED TO A FILE * | |
| **************************************************************/ | |
| const pdfFile = await TeaSchool.generatePdf(teaSchoolOptions); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment