Open johann-su opened 3 years ago
I am using pug as the templating engine for the html of the pdf. I import a few files (css, images etc.) inside the pug file but they don't show up in the template. I am using the base to point to the static files directory.
base
Here is my code: app.ts
app.post('/create-handout', async (req, res) => { const handout = pug.renderFile('./src/documents/handout.pug', req.body) pdf.create(handout, { format: 'A4', base: 'file://' + path.resolve('./src/documents/static') + '/' }).toFile('./src/result/result.pdf', (err) => { if (err) { res.send(Promise.reject()); } res.send(Promise.resolve()); }); })
handout.pug
html head title Handout link(rel='stylesheet', type='text/css', href='css/handout.css') body header img(src="img/header.svg") ...
You need to add localUrlAccess: true in your options as well as set the full file URL, file:///Users/.../img/header.svg https://github.com/marcbachmann/node-html-pdf/issues/618
localUrlAccess: true
file:///Users/.../img/header.svg
I am using pug as the templating engine for the html of the pdf. I import a few files (css, images etc.) inside the pug file but they don't show up in the template. I am using the
base
to point to the static files directory.Here is my code: app.ts
handout.pug