Home:ALL Converter>How can use pdfmake in ionic 2?

How can use pdfmake in ionic 2?

Ask Time:2017-02-10T05:05:50         Author:calraiden

Json Formatter

I'm trying to create pdf in ionic2 with pdfmake.

I added the library to my app:

$ npm install pdfmake --save

Import it into class

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

import * as pdfmake from 'pdfmake'

But, When I try to instantiate and use the method, the displayed error in the device:

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

How can I use pdfmake in ionic 2? Is it possible

enter image description here

Author:calraiden,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/42146857/how-can-use-pdfmake-in-ionic-2
yy