如何使用离子制作pdf生成器?

ami*_*nif 2 html pdf generator ionic2 angular

我想制作当前页面的 pdf,以便用户可以打印出来,但每个页面都是动态的,所以我需要一种文本到 pdf 生成器才能使其工作。

它是一个 ionic2 应用程序,就像一个食谱页面,所以你可以点击一个按钮,它只是从文本中生成一个 pdf。

你们知道我怎么能做到这一点吗?

小智 5

你最好的选择可能是这个插件:

https://github.com/cesarvr/pdf-generator

给你的动态页面部分一个像“pdf-area”这样的id,然后在你的.ts文件中选择它,如下所示:

let content = document.getElementById('pdf-area').innerHTML
Run Code Online (Sandbox Code Playgroud)

然后你可以把它变成一个文件或像这样打印

      cordova.plugins.pdf.htmlToPDF({
          data: content,
          type: "base64"
        },
          (success) => { 
           // you might have to turn the base64 into a binary blob to save it 
           // to a file at this point
        },

         (error) => console.log('error:', error);
   );

  }
Run Code Online (Sandbox Code Playgroud)