我需要将 View 呈现为 pdf,但来自 jquery get()
。它返回一个 View ,我尝试将返回的数据插入到 doc jsPDF()
中,但它不起作用!
View 包含所有内容、元数据、css 链接、js 链接和内容。
我的 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');
});
});
}
我该怎么做?
谢谢。
最佳答案
试试这个。
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');
};
关于javascript - jsPDF - 无法将 html 呈现为 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44915194/