使用jspdf导出PDF不渲染CSS [英] Exporting PDF with jspdf not rendering CSS
问题描述
我使用jspdf.debug.js从网站导出不同的数据,但有一些问题,我不能让它在导出的PDF中渲染CSS,如果我有一个图像在我的网页导出,PDF返回空白...
I am using jspdf.debug.js to export different data from a website but there are a few problems, I can't get it to render the CSS in the exported PDF and if I have an image in the page I am exporting, the PDF returns blank...
有没有人知道如何解决这个问题?
Does anyone know a way to fix this ?
显示未呈现CSS的 jsfiddle
和我的脚本
$(document).ready(function() {
$('#export').click(function(){
var d = new Date().toISOString().slice(0, 19).replace(/-/g, ""),
filename = 'financiar_' + d + '.pdf',
pdf = new jsPDF('p', 'pt', 'letter'),
specialElementHandlers = {
'#editor': function( element, renderer ) {
return true;
}
};
pdf.fromHTML(
$('.export').get(0) // HTML element
, 25 // x coord
, 25 // y coord
, {
'width': 550 // was 7.5, max width of content on PDF
, elementHandlers: specialElementHandlers
}
);
pdf.save( filename );
})
});
推荐答案
因为我知道jsPDF不能使用CSS
As i know jsPDF is not working with CSS and same issue i was facing.
为了解决这个问题,我使用了 Html2Canvas 只需添加HTML2Canvas JS ,然后使用 pdf.addHTML()而不是 pdf.fromHTML()。
To solve this issue , i used Html2Canvas So just Add HTML2Canvas JS and then use pdf.addHTML() instead of pdf.fromHTML().
这是我的代码(没有其他代码):
Here's my code (no other code):
var pdf = new jsPDF('p', 'pt', 'letter');
pdf.addHTML($('#ElementYouWantToConvertToPdf')[0], function () {
pdf.save('Test.pdf');
});
Best of Luck!
Best of Luck!
这篇关于使用jspdf导出PDF不渲染CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!