我尝试使用jsPDF从他的班级打印HTML表格到PDF但我从表格中得到了错误的大小。有没有办法解决这个问题,或者我做错了什么?
我的.js生成PDF的函数是:
$scope.demoFromHTML = function() {
var pdf = new jsPDF('l', 'pt', 'a4', true);
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
var source = $('#content')[0];
// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
var specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
var margins = {
top: 80,
bottom: 60,
left: 40,
width: 522
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(
source, // HTML string or DOM elem ref.
source.left, // x coord
source.top, { // y coord
'width': source.width, // max width of content on PDF
'elementHandlers': specialElementHandlers
},
function (dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save('Test.pdf');
}, margins
);
}
答案 0 :(得分:0)
您是否尝试更改宽度:522到宽度:边距对象中的source.width?
答案 1 :(得分:0)
仅使用jsPDF Autotable插件解决。 https://github.com/simonbengtsson/jsPDF-AutoTable