In my app external files provided by absolute path are not loaded properly, but in my template its all good. html-pdf v.2.2.0 https://www.npmjs.com/package/html-pdf/v/2.2.0
I provide a href to my styles template, but they are not loading during converting my HTML template into PDF file. It appears to have raw styles. Same thing goes with images, there are just question marks in the places of images.
<link rel="stylesheet" type="text/css" href="https://api.greenleafpolska.pl/public/sources/index.css">
In my app I'm serving static files through these line:
app.use('/public', express.static(path.join(__dirname, 'public')))
code generating the PDF file:
app.get("/", (req,res)=>{
fs.readFile('./template/index_min.html', 'utf8', function(error, data) {
if (!fs.existsSync(`./tst`)){
fs.mkdirSync(`./tst`);
}
fs.writeFile('./tst/out_min.html', data,
function (error){
if (error) throw error;
});
pdf.create(data, { format: 'Letter'})
.toFile('./tst/' + 1 + '_min.pdf', function(err, result) {
var file = fs.createReadStream('./tst/' + 1 + '_min.pdf');
var stat = fs.statSync('./tst/' + 1 + '_min.pdf');
res.setHeader('Content-Length', stat.size);
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', 'attachment; filename=' + 1 + '_min.pdf');
file.pipe(res);
});
});
})
Is there an other way to provide external files in template ? I have tried "base" html tag, but results are the same. Is this the library issue ?