我正在将 jsPDF 与 autotable 一起使用,我试图在生成的 pdf 页面上将表格以固定宽度居中。我似乎找不到解决方案,我看到的所有地方都是全宽,我不希望我的表格是全宽。我尝试使用边距选项,但它不是很精确,而且我不完全确定如何计算 A4 的边距以使表格水平居中。
document.querySelector(".report-btn").addEventListener("click", () => {
const pdfDoc = new jsPDF();
const list = createListforPdf(); // function to generate list
pdfDoc.autoTable({
theme: "grid",
tableWidth: 100,
styles: { halign: "center" },
columnStyles: {
0: { cellWidth: 85, halign: "left" },
1: { cellWidth: 15 }
},
head: [["MRZ Check number", "is OK?"]],
body: [[list[0], "YES"], [list[1], "NO"]]
});
pdfDoc.save();
});
Run Code Online (Sandbox Code Playgroud)