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
Import pdfmake in ionic 2 #864
Comments
Is not much to see from the screen, give full error stack in text (important as the line number). |
Sorry for the delay in reply. I created a new project and redo the steps, but the problem still. Creating blank project:
Installed lib:
Create an simple code to test: home.ts
home.html
Result in the browser test: Runtime Error
Ionic Framework: 2.1.0 |
Can you help me, please? |
@calraiden I've similar issue and usage of compiled version from build folder is helping me with that. |
Thank you for help. It's work. I cloned the compiled version into the www folder
Then I added the scripts to the index.
and replace import to ...
|
EXCEPTION: Error in :0:0 caused by: File 'Roboto-Regular.ttf' not found in virtual file system I follow your step in angular 2 project any help ? thanks :) |
Hi @rainstormza I already received similar error, it is the file not found. Please, check the includes:
|
Why include one with import and another one with <script>? You can do this for both.. import * as pdfmake from 'pdfmake/build/pdfmake';
import * as pdfFonts from 'pdfmake/build/vfs_fonts'; test if it loaded with console.log('pdfmake', window.pdfmake);
console.log('vfs', window.pdfmake.vfs); |
Hi @mnewmedia Honestly, I cannot be sure of the answer, but pdfmake only works with little workaround in my project (ionic2/angular2.) In my search on google, I read in some forum that pdfmake isn't yet fully compatible with angular2. Sorry, I did not do more advanced research to understand the reasons fully. |
This isn't about ionic2/angular more about TypeScript and module loading... I use ionic 1 with Typescript and it works for me with my code snippet above.. |
I understand your argument but unfortunately it doesn't work for me ionic2 and angular 2 =) without "workaround". Sorry again, I'm newbie with ionic, technically cann't answer "the why". |
@mnewmedia @calraiden thanks for helping :) I try to test with your solution @mnewmedia but error happens ERROR in /Users/ARM/Desktop/kibito_web/src/app/app.component.ts (14,26): Cannot find module 'pdfmake/build/pdfmake'.) I think this library doesn't have about @types for typescript yet. anyway, I made it with this solution in file .angular-cli.json
use this in component that you want to |
This could go in the readme IMO |
Here's what I had to do in Ionic 3 / Angular 4 with Webpack:
That last line just needs to be run once to move the output of the font script into the main pdfMake object. From then on PDFMake should work fine. (FWIW in my app I have one singleton @Injectable that does all my PDFMake work, so I put that line in its constructor.) This lets you operate totally out of the content in |
Thank you @ammulder - that did the trick for me! |
@ammulder Worked for me too! |
Actually, you don't need to "import as" syntax. Instead of: import * as pdfMake from 'pdfmake/build/pdfmake';
import * as pdfFonts from 'pdfmake/build/vfs_fonts'; You can import like this: import pdfMake from 'pdfmake/build/pdfmake';
import pdfFonts from 'pdfmake/build/vfs_fonts'; |
@ammulder Thanks a lot for your fix. :-) |
i'm try to use pdfmake and no success! <script src="cordova.js"></script> <script src='pdfmake/build/pdfmake.min.js'></script> <script src='pdfmake/build/vfs_fonts.js'></script><button ion-button (tap)="gerarPDF()"> import * as pdfmake from 'pdfmake/build/pdfmake'; public gerarPDF(){ |
Hi, I installed pdfmake in ionic 2 by npm
npm install pdfmake --save
And import to into class
import pdfmake from 'pdfmake';
orimport * as pdfmake from 'pdfmake';
but, when I try use ...
receive Runtime Error:
fs.readFileSync is not a function
The text was updated successfully, but these errors were encountered: