Open DevMuneeb opened 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
I use mustache.js to create my PDF template HTML.
Mustache is a template engine not pdf creator
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 woff2In my case I did:
`
/* inter-regular - latin */
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 400;
src: local(''),
url('<%= base %>/fonts/inter-v3-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
url('<%= base %>/fonts/inter-v3-latin-regular.woff') format('woff'), /* Modern Browsers */
}
/* inter-500 - latin */
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 500;
src: local(''),
url('<%= base %>/fonts/inter-v3-latin-500.woff2') format('woff2'), /* Super Modern Browsers */
url('<%= base %>/fonts/inter-v3-latin-500.woff') format('woff'), /* Modern Browsers */
}
/* inter-600 - latin */
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 600;
src: local(''),
url('<%= base %>/fonts/inter-v3-latin-600.woff2') format('woff2'), /* Super Modern Browsers */
url('<%= base %>/fonts/inter-v3-latin-600.woff') format('woff'), /* Modern Browsers */
}
/* inter-700 - latin */
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 700;
src: local(''),
url('<%= base %>/fonts/inter-v3-latin-700.woff2') format('woff2'), /* Super Modern Browsers */
url('<%= base %>/fonts/inter-v3-latin-700.woff') format('woff'), /* Modern Browsers */
}
/* inter-800 - latin */
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 800;
src: local(''),
url('<%= base %>/fonts/inter-v3-latin-800.woff2') format('woff2'), /* Super Modern Browsers */
url('<%= base %>/fonts/inter-v3-latin-800.woff') format('woff'), /* Modern Browsers */
}
/* inter-900 - latin */
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 900;
src: local(''),
url('<%= base %>/fonts/inter-v3-latin-900.woff2') format('woff2'), /* Super Modern Browsers */
url('<%= base %>/fonts/inter-v3-latin-900.woff') format('woff'), /* Modern Browsers */
}
`
...........................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{
.................................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>
}