如何使用 JQuery pdfHtml5 将整个 DataTable 居中

How do I center the entire DataTable in the pdf using JQuery pdfHtml5

我喜欢使用 $('#tableId').DataTable() 和 "pdfHtml5" 按钮生成 PDF。我只是不知道如何在生成的 PDF 中将信息居中。

只有两列的 Table 出现在 .pdf 的左侧,但如果它只是居中看起来会好得多。

我很确定它应该在按钮中完成,但还没有完全弄清楚最后一点。

当前示例(不太有效):

extend:"pdfHtml5",
className: "btn",
text: "Export To PDF",
title: "PDF Title",
filename: "AFileName",
messageTop: "Test Message",

// And this is where I think I'm close...
customize: function(doc) {
    // doc ? = ?
}

有什么想法吗?

我通常使用 html 然后我使用 jquery 转换为 pdf。总结一下我使用 Jquery 和 JsPDF.

但您可以在此处获得更多信息 https://datatables.net/reference/button/

查看 doccontent 部分。第二个索引是 table 元素。您可以使用例如

强制左/右页边距
customize: function(doc) {
  doc.content[1].margin = [ 100, 0, 100, 0 ] //left, top, right, bottom
}

这将使 table 居中,根据您的需要设置值。查看了文档,似乎没有办法自动 "center" 页面内容。有 alignment 选项,但这些选项用于渲染内容中的文本对齐(例如 table)。