2017-02-09 33 views
5

Próbuję utworzyć pdf w ionic2 z pdfmake.Jak korzystać z pdfmake w ionic 2?

dodałem biblioteki do mojej aplikacji:

$ npm install pdfmake --save 

zaimportować go do klasy

import { Component } from '@angular/core'; 
import { NavController, NavParams, LoadingController, ToastController, AlertController } from 'ionic-angular'; 

import * as pdfmake from 'pdfmake' 

ale gdy próbuję instancję i użyj metody, wyświetlany błąd w urządzeniu:

var dd = { 
    content: [ 
     'First paragraph', 
     'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines' 
    ], 
    pageSize: 'A4', 
    pageMargins: [25, 25, 25, 25], 
}; 

// download the PDF 
var pdf = new pdfmake(); 
pdf.createPdf(dd).download(); 

Runtime Error:

fs.readFileSync is not a function 

Jak mogę użyć pdfmake w ionic 2? Czy to możliwe,

enter image description here

+0

Próbowałeś import pdfmake od 'pdfmake'? Moduły CommonJS i wszystkie – misha130

+0

Tak, próbuję bez *, ale nie działa ze mnie. –

+0

@ misha130 o "Moduły CommonJS i wszystkie", przepraszam, nie rozumiem –

Odpowiedz

1

Więc ... znowu ... Po wielu dniach, w końcu uzyskać pdfmake do pracy nad moim projekcie z pomocą pdfmake społeczności.

I sklonowany wersję skompilowaną do folderu www

$ cd project/www/ 
$ git clone https://github.com/bpampuch/pdfmake.git 

Potem dodaje skrypty do indeksu.

<body> 

    <!-- Ionic's root component and where the app will load --> 
    <ion-app></ion-app> 

    <!-- The polyfills js is generated during the build process --> 
    <script src="build/polyfills.js"></script> 

    <!-- The bundle js is generated during the build process --> 
    <script src="build/main.js"></script> 
    <script src='pdfmake/build/pdfmake.min.js'></script> 
    <script src='pdfmake/build/vfs_fonts.js'></script> 
</body> 
</html> 

i zastąpić import do ...

import * as pdfmake from 'pdfmake/build/pdfmake'; 

Pdfmake community response

Github with project test

+1

Kiedy dodaję taki projekt w Ionic 2 "klon https://github.com/bpampuch/pdfmake.git" daje mnie błąd "klon" nie jest rozpoznawany jako polecenie wewnętrzne lub zewnętrzne, program operacyjny lub plik wsadowy –

+0

@ShehramTahir przykro nam, mały błąd z poleceniem git –