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

Can not import customfonts in React #1974

Closed
ghost opened this issue Sep 29, 2018 · 2 comments
Closed

Can not import customfonts in React #1974

ghost opened this issue Sep 29, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Sep 29, 2018

I want to use customfonts in React app, but I can't import the default_vfs file to my project

import jsPDF from 'jspdf';
import 'jspdf-customfonts';

I also tried to import default_vfs file like:

import jsPDF from 'jspdf';
import 'jspdf-customfonts';
import 'jspdf-customfonts/dist/default_vfs';

But it doesn't work, console error repoting is

Uncaught ReferenceError: jsPDF is not defined

I don't konw what should I do to make it work properly

@Uzlopak
Copy link
Collaborator

Uzlopak commented Sep 29, 2018

Why you important jspdf-customfonts?

@pippo111
Copy link

pippo111 commented Oct 1, 2018

You don't need to import jspdf-customfonts as addFileToVFS is built in jsPdf itself

You can use jspdf-customfonts as a tool for making base64 from from ttf file (node makefonts.js) then just use generated data in jsPdf.

const someFont = 'AAEAAAASAQAABAAgRkZUTW...'
doc.addFileToVFS('some-font.ttf', someFont)
doc.addFont('some-font.ttf', 'some-font', 'normal')
doc.setFont(`someFont`)

@Uzlopak Uzlopak closed this as completed Nov 2, 2018
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

2 participants