Last active
July 17, 2019 11:49
-
-
Save AmirTugi/5c0a2ad2b8566c938e7bb9dfb36105f7 to your computer and use it in GitHub Desktop.
This file contains 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 BUFFER 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