(element, filePath, callback)
| 3 | import { pdf } from '../index'; |
| 4 | |
| 5 | export const renderToFile = async (element, filePath, callback) => { |
| 6 | const instance = pdf(element); |
| 7 | const output = await instance.toBuffer(); |
| 8 | const stream = fs.createWriteStream(filePath); |
| 9 | |
| 10 | output.pipe(stream); |
| 11 | |
| 12 | return new Promise((resolve, reject) => { |
| 13 | stream.on('finish', () => { |
| 14 | if (callback) callback(output, filePath); |
| 15 | resolve(output); |
| 16 | }); |
| 17 | stream.on('error', reject); |
| 18 | }); |
| 19 | }; |
| 20 | |
| 21 | export default renderToFile; |