1
1
const puppeteer = require ( 'puppeteer' ) ;
2
2
var Promise = require ( 'bluebird' ) ;
3
3
const hb = require ( 'handlebars' )
4
-
4
+ const inlineCss = require ( 'inline-css' )
5
5
module . exports
6
6
async function generatePdf ( file , options , callback ) {
7
7
// we are using headless mode
@@ -20,10 +20,11 @@ async function generatePdf(file, options, callback) {
20
20
const page = await browser . newPage ( ) ;
21
21
22
22
if ( file . content ) {
23
+ data = await inlineCss ( file . content , { url :"/" } ) ;
23
24
console . log ( "Compiling the template with handlebars" )
24
25
// we have compile our code with handlebars
25
- const template = hb . compile ( file . content , { strict : true } ) ;
26
- const result = template ( file . content ) ;
26
+ const template = hb . compile ( data , { strict : true } ) ;
27
+ const result = template ( data ) ;
27
28
const html = result ;
28
29
29
30
// We set the page content as the generated html by handlebars
@@ -61,10 +62,11 @@ async function generatePdfs(files, options, callback) {
61
62
const page = await browser . newPage ( ) ;
62
63
for ( let file of files ) {
63
64
if ( file . content ) {
65
+ data = await inlineCss ( file . content , { url :"/" } )
64
66
console . log ( "Compiling the template with handlebars" )
65
67
// we have compile our code with handlebars
66
- const template = hb . compile ( file . content , { strict : true } ) ;
67
- const result = template ( file . content ) ;
68
+ const template = hb . compile ( data , { strict : true } ) ;
69
+ const result = template ( data ) ;
68
70
const html = result ;
69
71
// We set the page content as the generated html by handlebars
70
72
await page . setContent ( html , {
0 commit comments