Closed MarkSalabutin closed 5 years ago
How to use pdfmake is described in readme in Getting Started section and see how to use in javascript frameworks.
I've already done this, but I still have this error
You do not include pdfmake to your script. Without some informations, and sample of your code, can not help. You use some js framework?
Yes, I'm using React.js. That's how I init pdfmake package
import pdfMake from "pdfmake/build/pdfmake";
import pdfFonts from "pdfmake/build/vfs_fonts";
pdfMake.vfs = pdfFonts.pdfMake.vfs;
@MarkSalabutin did you ever figure this out?
Your usage is from example in readme, and it works correctly. If not, problem will be in react application, try to ask on react support.
@MarkSalabutin You using this import method. This is work for me. import as pdfMake from 'pdfmake/build/pdfmake'; import as pdfFonts from 'pdfmake/build/vfs_fonts'; pdfMake.vfs = pdfFonts.pdfMake.vfs;
There was a problem in my bundler. I shouldn't compile dependencies.
@poomarimuruganD That worked for me. Thanks.
You using this import method. This is work for me. import as pdfMake from 'pdfmake/build/pdfmake'; import as pdfFonts from 'pdfmake/build/vfs_fonts'; pdfMake.vfs = pdfFonts.pdfMake.vfs;
This worked for me and saved me so much time!! Thank you!
Hi @MarkSalabutin, I know it's been a while, but maybe you can share what particularly have you updated to get rid of this issue? I started facing this issue during my unit-tests run after installing completely another package. And now I'm wondering what should I update to make it work. Thanks in advance!
Hello, I will be glad to help out, what I did is, instead of doing the import like the commented out way, I used "import * as" which resolved my issue. For all the solution except this, I used this site:https://www.ngdevelop.tech/angular-8-export-to-pdf-using-pdfmake/
Let me know if your issue is resolved! //import {pdfMake} from 'pdfmake/build/pdfmake';
//import {pdfFonts} from 'pdfmake/build/vfs_fonts';
import * as pdfMake from 'pdfmake/build/pdfmake';
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
pdfMake.vfs = pdfFonts.pdfMake.vfs;
On Friday, August 5, 2022 at 05:59:53 AM CDT, Dmytro Shvetsov ***@***.***> wrote:
Hi @MarkSalabutin, I know it's been a while, but maybe you can share what particularly have you updated to get rid of this issue? I started facing this issue during my unit-tests run after installing completely another package. And now I'm wondering what should I update to make it work. Thanks in advance!
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
Hi @merrakokebie! Thanks a lot for your response! Unfortunately, your suggestion didn't resolve my issue. By the way, I'm using precisely your way of importing and initialising pdf-stuff in my React-component. I don't have troubles during my development or running the app. Issue was occurred on stage of unit-testing and for current moment I'm not sure way. Some time ago I read something about NodeJS
versions (because in our project we use pretty old v12
), so maybe bumping up NodeJS
version will help me, but for now I just skip broken tests :(
I'll come back to you with updates, if I find appropriate solution, to share with you.
Ok. Thank you for the update. I hope Node js update will work for you. I am using the latest node. Merra
On Mon, Aug 8, 2022 at 4:54 AM, Dmytro @.***> wrote:
Hi @merrakokebie! Thanks a lot for your response! Unfortunately, your suggestion didn't resolve my issue. By the way, I'm using precisely your way of importing and initialising pdf-stuff in my React-component. I don't have troubles during my development or running the app. Issue was occurred on stage of unit-testing and for current moment I'm not sure way. Some time ago I read something about NodeJS versions (because in our project we use pretty old v12), so maybe bumping up NodeJS version will help me, but for now I just skip broken tests :( I'll come back to you with updates, if I find appropriate solution, to share with you.
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
@merrakokebie did you manage to find a solution to this?
estou tendo um problema parecido:
"TypeError: Cannot read properties of undefined (reading 'vfs')"
e estou iniciando o arquivo com
import * as pdfMake from "pdfmake/build/pdfmake";
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
pdfMake.vfs = pdfFonts.pdfMake.vfs;
FINALLY THIS CODE WORKED FOR ME 😪
import * as pdfMake from 'pdfmake/build/pdfmake';
import * as jszip from 'jszip';
pdfMake.vfs = {};
pdfMake.jszip = jszip;
pdfMake.DynamicContent = {
content: {
widths: '100%'
}
};
pdfMake.fonts = {
Roboto: {
normal: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-Regular.ttf',
bold: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-Medium.ttf',
italics: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-Italic.ttf',
bolditalics: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-MediumItalic.ttf'
},
};
export default pdfMake;
Guys I just coppied roboto object from route and put it in a js file and just used it, Here my code,
import * as pdfMake from "pdfmake/build/pdfmake";
import roboto from "../../../assets/fonts/roboto.js"
pdfMake.vfs = roboto;
my robot.js file like below
export default{
"Roboto-Italic.ttf": "AAEAAAARAQAABAAQR0RFRqbzo4gAAddgAAACWEdQT1N/jKrdAAHZuAAAWMBHU1VCm18k/
....}
And this after import also works:
pdfMake.vfs = window.pdfMake.vfs
On application start I have this error: