blikblum / pdfmake-utils Goto Github PK
View Code? Open in Web Editor NEWHelper classes to use with PdfMake
License: MIT License
Helper classes to use with PdfMake
License: MIT License
Investigate if/how can be done
Hi,
is it possible to add standard fonts dynamically for pdf creation? (Browser)
I tested following script but it does not work:
assetsLoader.registerFont({
name: 'Courier',
fileName: 'Courier',
URL: 'assets/font/data/Courier.afm',
styles: ['normal']
});
Error:
ERROR Error: "File '../font/data/Courier.afm' not found in virtual file system"
It seems that the standard font are only stored in pdfMake.rawFiles
and not processed further on.
Implement option to prefetch assets (fonts / files)
Try to use platform link prefetch
Hi, @blikblum . First, thanks for you awesome work with pdfmake-lite and pdfmake-utils.
We're using them on production and they helped us in reducing our bundle size.
I'm opening this issue over this repository because I didn't finded the proper repository for pdkmake-lite, so sorry by that. We noticed that pdfmake-lite is behind pdfmake by some versions, being 0.1.65 the last one.
Thanks!
Hi,
I am testing this library but unfortunately can't make it work. Here is what I am trying to do. At this point I am literally copying your example from README.
const pdfContent = {
content: ["My test"],
};
const assetsLoader = new PdfAssetsLoader();
pdfMake.fonts = assetsLoader.fonts;
pdfMake.vfs = assetsLoader.vfs;
// register Roboto font, normal variant. Roboto-Regular.woff must be in root path
assetsLoader.registerFont({
name: "Roboto",
fileName: "Roboto-Regular.woff",
styles: ["normal"],
});
// register Roboto font, bolditalics variant using a custom file location
assetsLoader.registerFont({
name: "Roboto",
fileName: "Roboto-MediumItalic.woff",
URL: "fonts/Roboto-MediumItalic.woff",
styles: ["bolditalics"],
});
// register a file to be loaded in the root path
assetsLoader.registerFile({ name: "MyLogo.png" });
// register a file with a custom location
assetsLoader.registerFile({
name: "MyHeader.png",
URL: "images/sunshine.png",
});
assetsLoader
.load()
.then(() => {
console.log("assets loaded");
})
.catch((errors) => {
// errors -> array with all file loading errors
console.error("assets loading", errors);
});
pdfMake
.createPdf(pdfContent)
.download("mytest.pdf");
and the error in browser console says:
Uncaught (in promise) Error: Font 'Roboto' in style 'normal' is not defined in the font section of the document definition.
at FontProvider.provideFont (pdfmake.min.js:2:580246)
at pdfmake.min.js:2:103003
at Array.forEach (<anonymous>)
at measure (pdfmake.min.js:2:102066)
at TextTools.buildInlines (pdfmake.min.js:2:103564)
at DocMeasure.measureLeaf (pdfmake.min.js:2:600645)
at pdfmake.min.js:2:598540
at StyleContextStack.auto (pdfmake.min.js:2:163364)
at DocMeasure.measureNode (pdfmake.min.js:2:597427)
at DocMeasure.measureVerticalContainer (pdfmake.min.js:2:601611)
Any idea of what I'm doing wrong?
thank you very much
Add a class that handles loading assets as well the pdfMake bundle
Should accept fonts and files as params and a ready method
Example:
const fonts = {
Roboto: {italics: '[url]'}
}
const pdfMake = new LazyPdfMake({fonts})
await pdfMake.ready()
pdfMake.instance // actual pdfMake
pdfMake.fileExists('[filePath]')
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.