简体   繁体   English

jsPDF-无法将html渲染为pdf

[英]jsPDF - Cannot render html to pdf

I need to render a view to pdf but from a jquery get() . 我需要从jQuery get()渲染到pdf的视图。 It returns a view and I try to insert this returned data in doc jsPDF() but it doesn't work! 它返回一个视图,我尝试将此返回的数据插入doc jsPDF()但是它不起作用!

The view have the all, metadata, css links, js links and the content. 该视图具有全部,元数据,css链接,js链接和内容。

My jquery function: 我的jQuery函数:

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. 谢谢。

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');
};

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

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