gpt4 book ai didi

javascript - 如何使用 jsPDF 从具有表格全尺寸的 HTML 表格正确生成 PDF

转载 作者:行者123 更新时间:2023-11-28 02:35:15 26 4
gpt4 key购买 nike

我正在尝试使用 jsPDF 将他的类(class)中的 HTML 表格打印成 PDF,但我从表格中得到的尺寸有误。有没有办法解决这个问题,还是我做错了什么?

Full Table

PDF Generated

我生成 PDF 的 .js 函数是:

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

最佳答案

您是否尝试将边距对象中的 width: 522 更改为 width: source.width ?

关于javascript - 如何使用 jsPDF 从具有表格全尺寸的 HTML 表格正确生成 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47461885/

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