marcbachmann / node-html-pdf

This repo isn't maintained anymore as phantomjs got dreprecated a long time ago. Please migrate to headless chrome/puppeteer.
MIT License
3.56k stars 545 forks source link

unable to apply custom font #637

Open DevMuneeb opened 3 years ago

DevMuneeb commented 3 years ago

...........................server.js..........................................

var accessPath = path.join('file://', __dirname, '/public')

var options={ quality:"75", formaat:"A4", base:accessPath }; pdf.create(pdfTemplate(data),options).toBuffer((err,buffer)=>{ if(err){ res.status(400).send(Promise.reject()) }else{

            res.status(200).send(buffer);
        }

.................................pdf Template.js..................................................... module.exports=(data)=>{ const startdate=data.Starts.split(" ")[0]; const enddate=data.Ends.split(" ")[0]; const description=(data.Description.length > 200 || data.Description.length ===0)?data.Title :data.Description; return ` <!DOCTYPE html>

Document
${description}
12/03/2021 - 18/07/2021
${data.Code}
Copie e vá para a loja
`

}

alinjf commented 3 years ago

address to your font files are not ok you have to think that the template is serve on a web server and addres it to it

xinthose commented 3 years ago

I use mustache.js to create my PDF template HTML.

alinjf commented 3 years ago

Mustache is a template engine not pdf creator

ahmed-alii commented 2 years ago

1- Use Google web fonts helper to download web font files. (https://google-webfonts-helper.herokuapp.com/fonts) 2- Include all fonts you need in your CSS file. If you are having issues including your CSS files, a quick workaround is to use styling inside your tag. 3- Remove all lines with font's src other than woff and woff2

In my case I did:

``