简体   繁体   English

如何在离子应用程序中从 HTML 生成 PDF

[英]how to generate PDF from HTML in ionic app

I would like to generate a PDF from a HTML page, I'm using CORDOVA.PDF.GENERATOR plugin.我想从 HTML 页面生成 PDF,我正在使用CORDOVA.PDF.GENERATOR插件。 It generates the PDF but without style, I want the generated PDF with the same style as the HTML page .它生成 PDF 但没有样式,我希望生成的 PDF 具有与 HTML 页面相同的样式。

I need to tell the plugin to style the page with the same styling.我需要告诉插件以相同的样式设置页面的样式。 How can I do that?我怎样才能做到这一点?

Heading标题

let options = {
  documentSize: 'A4',
  type: 'share',
  fileName: 'myFile.pdf'
};
cordova.plugins.pdf.fromData(page[0].innerHTML, options)

Try this尝试这个

  var payload = _.template(' <head><link rel="stylesheet" href="<%=css_file%>">
   </head><body> <h1> Hello World </h1></body>')

    cordova.plugins.pdf.fromData((payload({css_file: cssFile}),opts)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM