mostafa
mostafa

Reputation: 1

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. It generates the PDF but without style, I want the generated PDF with the same style as the HTML page .

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)

Upvotes: 0

Views: 1750

Answers (1)

Muhammad Rameez
Muhammad Rameez

Reputation: 80

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)

Upvotes: 1

Related Questions