0
我在離子2框架(基於angularjs2)中創建應用程序。我在這裏提供論壇中的數據,這些數據以pdf格式顯示。 任何人都可以請告訴如何安裝pdfmake在angularjs2或離子2和一些基本的片段使用。在Angularjs2/Ionic2中實現pdfmake
我在離子2框架(基於angularjs2)中創建應用程序。我在這裏提供論壇中的數據,這些數據以pdf格式顯示。 任何人都可以請告訴如何安裝pdfmake在angularjs2或離子2和一些基本的片段使用。在Angularjs2/Ionic2中實現pdfmake
我試圖找到解決這個問題。我碰到一個Plunker這裏,可以幫助你:https://plnkr.co/edit/7tPFTAjKWwaRp1IbT0Tg?p=preview
你需要(通過亭子安裝pdfmake)
然後引用您的index.html文件與鮑爾你的工程安裝pdfmake
<script src='pdfmake.min.js'></script>
<script src='vfs_fonts.js'></script>
(它可以幫助你在兩個js文件移動到同一個文件中的index.html)
那麼你需要一個js文件實際構建PDF文檔(這在例如plunker看起來像這樣:)
function buildPdf(value) {
var pdfContent = value;
var docDefinition = {
content: [{
text: 'My name is: '
}]
}
console.log(pdfContent);
return docDefinition;
}
你使用你的組件是這樣的(其中「出口級應用」是組件的名稱):
export class App {
public item: {firstName: string, lastName: string} = {firstName: 'Peter', lastName: 'Parker'};
pdf: any;
buildPdf: any = new buildPdf();
openPdf() {
this.pdf = pdfMake;
this.buildPdf = buildPdf;
this.pdf.createPdf(buildPdf(this.item)).open();
}
}
我希望這有助於!