Skip to content
This repository has been archived by the owner on Feb 28, 2019. It is now read-only.

Plan on adding custom fonts? (Feature Request) #25

Open
HackbrettXXX opened this issue Oct 31, 2017 · 3 comments
Open

Plan on adding custom fonts? (Feature Request) #25

HackbrettXXX opened this issue Oct 31, 2017 · 3 comments

Comments

@HackbrettXXX
Copy link
Contributor

Hello there,

first of all, thanks for this great effort to add arbitrary fonts to jsPDF. We are currently integrating this plugin into our fork https://github.com/yWorks/jsPDF in order to be able to use custom fonts with svg2pdf.js.

We are quite happy with the progress this project is making recently. However, we miss the functionality to comfortably add custom fonts. Either at runtime on the browser or with a small build tool that generates a file like "defaultVFS.js" from font files. What would also be great is support for other font formats like WOFF/WOFF2 or SVG-Fonts.

What are your plans concerning this features?

Greetings,
Hackbrett

@HackbrettXXX
Copy link
Contributor Author

I just saw the VFS-generation tool. Great!

For WOFF/SVG conversion this package might come in handy:
https://www.npmjs.com/package/fonteditor-core

@sphilee
Copy link
Owner

sphilee commented Nov 8, 2017

@HackbrettXXX
I applied the code to the package you gave me. Applying this code seems to be usable for pdf conversion except for some font formats. However, the big problem is that 'fonteditor-core' takes too long.

const Font = require('fonteditor-core').Font;
const fs = require('fs');

const path = './fonts/';
fs.readdir(path, (err, files) => {
    if (err) console.log(err);

    const fontList = files.map(file => {
        const format = file.split('.')[1];
        const base64Conetent = Font.create(fs.readFileSync(path + file), {
            type: format
        }).toBase64({
            type: 'ttf'
        }).split(',')[1];
        return `jsPDFAPI.addFileToVFS('${file}','${base64Conetent}');`;
    });
    fs.writeFileSync('./dist/default_vfs.js', `(function (jsPDFAPI) {\n${fontList.join('\n')}\n})(jsPDF.API);`);
})

@HackbrettXXX
Copy link
Contributor Author

@sphilee
Yeah, I tested it myself and it didn't work for the fonts I tested.

I made some small improvements: #28

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

No branches or pull requests

2 participants