running example code with node 8.11.2 get "Error: ENOENT: no such file or directory, open 'fonts/PalatinoBold.ttf"
See original GitHub issue
PDFDocument = require ('pdfkit');
const fs = require('fs');
// Create a document
doc = new PDFDocument
// Pipe its output somewhere, like to a file or HTTP response
// See below for browser usage
doc.pipe (fs.createWriteStream('output.pdf'))
// Embed a font, set the font size, and render some text
doc.font('fonts/PalatinoBold.ttf')
.fontSize(25)
.text('Some text with an embedded font!', 100, 100)
// Add another page
doc.addPage()
.fontSize(25)
.text('Here is some vector graphics...', 100, 100)
// Draw a triangle
doc.save()
.moveTo(100, 150)
.lineTo(100, 250)
.lineTo(200, 250)
.fill("//FF3300")
// Apply some transforms and render an SVG path with the 'even-odd' fill rule
doc.scale(0.6)
.translate(470, -380)
.path('M 250,75 L 323,301 131,161 369,161 177,301 z')
.fill('red', 'even-odd')
.restore()
// Add some text with annotations
doc.addPage()
.fillColor("blue")
.text('Here is a link!', 100, 100)
.underline(100, 100, 160, 27, "//0000FF")
.link(100, 100, 160, 27, 'http://google.com/')
// Finalize PDF file
doc.end()
trying to run the code from pdfkit site get the error
Error: ENOENT: no such file or directory, open 'fonts/PalatinoBold.ttf'
at Object.fs.openSync (fs.js:646:18)
at Object.fs.readFileSync (fs.js:551:33)
at Object.fontkit.openSync (/root/node_modules/fontkit/index.js:43:19)
at Function.PDFFont.open (/root/node_modules/pdfkit/js/font.js:14:24)
at PDFDocument.font (/root/node_modules/pdfkit/js/mixins/fonts.js:39:28)
at Object.<anonymous> (/root/nodeFiles/pdfCreator.js:15:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:7
Top Results From Across the Web
How to solve Error: ENOENT: no such file or directory
Run install your dependencies, clean your cache, and develop your project by: npm install; gatsby clean; gatsby develop. If the error ...
Read more >palatino-Bold, palatino-Roman, palatino-Italic belongs to ...
URWPalatino is the Palatino clone shipped with TeX Live and MiKTeX. There are licensing problem in using the Adobe fonts. – egreg. Jan...
Read more >SUSE Linux Enterprise Desktop - Ayuntamiento de Zaragoza
This guide is intended for use by professional network and system administrators during the actual planning, deployment, configuration, ...
Read more >Palatino® Bold Italic | Fonts.com
Select Font Format; Add to Wish List. Try it; Waterfall; Character Map; OpenType; Technical Details. Desktop Web Font. Try this font now!
Read more >SUSE Linux Enterprise Desktop 文档
Windows 网络SUSE Linux Enterprise Desktop 支持用Active Directory 作为. 鉴定源。它为您提供了安全而稳定的Linux 操作系统的一切优点,同时还提.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi all I was just running into this same issue and believe I found the solution
After specifying the fonts path relative to
__dirname
, the font loaded.e.g.
Hope this helps anyone having the same problem!
This solve my issue put your image like this