user3242861
user3242861

Reputation: 1929

jsPDF - Cannot render html to pdf

I need to render a view to pdf but from a jquery get(). It returns a view and I try to insert this returned data in doc jsPDF() but it doesn't work!

The view have the all, metadata, css links, js links and the content.

My jquery function:

function exportToPdf()
{
  $('#exportToPdf').on('click', function(e)
  {
    var ref = $(this).attr('data-ref');

    $.get("/to-pdf/"+encodeURIComponent(ref), function(data)
    {
      var doc = new jsPDF();
      doc.text(data, 10, 10);
      doc.save('a4.pdf');
    });
  });
}

How can I do that?

Thank you.

Upvotes: 2

Views: 4459

Answers (1)

Bajinder Budhwar
Bajinder Budhwar

Reputation: 83

Try this.

function onClick() {
  var pdf = new jsPDF('p', 'pt', 'letter');
  pdf.canvas.height = 80 * 11;
  pdf.canvas.width = 80 * 8.5;    
  pdf.fromHTML(document.body); //Your HTML content goes here
  pdf.save('test.pdf');
};

Upvotes: 3

Related Questions