本文介绍了如何在离子2中使用pdfmake?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用pdfmake在ionic2中创建pdf。
I'm trying to create pdf in ionic2 with pdfmake.
我将库添加到我的应用中:
I added the library to my app:
$ npm install pdfmake --save
导入它进入班级
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();
运行时错误:
fs.readFileSync is not a function
如何在离子2中使用pdfmake ?是否有可能
How can I use pdfmake in ionic 2? Is it possible
推荐答案
所以......再次......经过很多天,我终于通过pdfmake社区的帮助获得pdfmake来处理我的项目。
So... again... After many days, I finally get the pdfmake to work on my project with pdfmake community's help .
我克隆了编译版本进入www文件夹
I cloned the compiled version into the www folder
$ cd project/www/
$ git clone https://github.com/bpampuch/pdfmake.git
然后我将脚本添加到索引中。
Then I added the scripts to the index.
<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>
并将导入替换为...
and replace import to ...
import * as pdfmake from 'pdfmake/build/pdfmake';
这篇关于如何在离子2中使用pdfmake?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!