Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to require TTFFont with Browserify? #354

Closed
backspace opened this issue Dec 29, 2014 · 4 comments
Closed

Is there a way to require TTFFont with Browserify? #354

backspace opened this issue Dec 29, 2014 · 4 comments

Comments

@backspace
Copy link
Contributor

Hey, thanks for this library.

I need to embed a custom font in a browser-generated PDF. It seems that’s not currently possible, but if I could instantiate a TTFFont in my build step with TTFFont.open("path/to/font", "Font Name"), (I think?) I could pass it to doc.font when I’m generating the PDF.

Is there a way to require TTFFont? I’m not Node-experienced enough to know how, my naïve attempts like require('pdfkit').TTFFont and require('pdfkit/font/ttf') have all failed.

Or maybe I should just read the .ttf into a buffer myself?

@devongovett
Copy link
Member

You can load the ttf into an arraybuffer using ajax and pass that to doc.font. See here: #340 (comment). I need to add this to the docs as there have been many questions about this.

@backspace
Copy link
Contributor Author

It worked. Thanks so much!

@zacronos
Copy link

zacronos commented Jan 5, 2015

It is also possible to bypass the AJAX call if you want to embed the font data into your javascript directly. First, you need to include this Buffer implementation: https://github.com/feross/buffer

Then, you will need to base64-encode the contents of the file somehow.

Finally, do something like:

var myFont = Buffer("...base64-font-data...", "base64");
doc.font(myFont, 12)

@devongovett
Copy link
Member

If you're using browser, I recommend brfs to automatically turn fs.readFileSync calls into inline buffers, like you described above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants