我正在使用 pdfmake 生成 PDF 客户端。它在 Chrome 上运行良好:我得到一个在新标签页中打开的 base64 编码 URL。
但是,在我在 android 上的 Cordova 应用程序上,它不起作用,所以我想将 PDF 写入设备。当我使用 jsPDF doc.output() 时,我设法以这种格式将 pdf 写入文件:
%PDF-1.3
3 0 obj
<</Type /Page... etc
有谁知道如何使用 pdfmake 获取此 PDF 代码?
因此,在再次查看 pdfmake.js 之后,我设法使用以下代码将我的 PDF 写入 android 设备上的文件:
pdfMake.createPdf(docDefinition).getBase64(function(base64){
// Decode base64 enocded PDF
pdf = atob(base64);
console.log(pdf);
// Write to device
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
});