gpt4 book ai didi

javascript - 如何从 html 和文本创建带有 jspdf 的 pdf?

转载 作者:行者123 更新时间:2023-11-30 07:08:30 24 4
gpt4 key购买 nike

我需要将我的 html 内容和文本一起打印,我尝试使用以下代码,但添加的文本未打印在 PDF 中。它只打印 html 内容。请帮我解决这个问题....

    pdf = new jsPDF('l', 'mm', 'ledger'),
specialElementHandlers = {
'#editor': function( element, renderer ) {
return true;
}
};
pdf.fromHTML(
$('#customers').get(0) // HTML element
, 15 // x coord
, 0.5 // y coord
, {
'width': 3000 // was 7.5, max width of content on PDF
, elementHandlers: specialElementHandlers
}
);
pdf.text(35, 25, "test");
pdf.save( filename );
});

最佳答案

您必须使用 function 的完整语法:

doc.fromHTML(HTML, x, y, settings, callback, margins);

使用回调,您可以添加一个在 fromHtml complete 上执行的函数。

在您的代码中:

pdf = new jsPDF('l', 'mm', 'ledger'),
specialElementHandlers = {
'#editor': function( element, renderer ) {
return true;
}
};
pdf.fromHTML(
$('#customers').get(0) // HTML element
, 15 // x coord
, 0.5 // y coord
, {
'width': 3000 // was 7.5, max width of content on PDF
, elementHandlers: specialElementHandlers
},
myfunc,
{
top : 25,
bottom : 25
}
);

function myfunc(){
pdf.text(35, 25, "test");
pdf.save( filename );
}

关于javascript - 如何从 html 和文本创建带有 jspdf 的 pdf?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28430580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com