- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用pdfhtml导出数据表这是我的代码
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [ {
extend: 'pdfHtml5',
text: 'PDF with image'
} ]
} );
} );
结果导出 pdf 像这样
最佳答案
您可以使用customize
回调来更改生成的PDF的布局。它没有很好的记录(我猜),但请参阅 PDFMake definition object docs要了解命名和对象结构,请参阅 this answer (由我)作为一个非常简单的例子来说明如何做。
据我所知,没有任何选项可以让您强制将整个内容居中(即一种 docDefinition.content.align
或类似的),但您可以否决页边距和列宽。
$('#example').DataTable({
dom: 'Bfrtip',
buttons: [ {
extend: 'pdfHtml5',
text: 'PDF with image',
customize: function(doc) {
//pageMargins [left, top, right, bottom]
doc.pageMargins = [ 150, 20, 150, 20 ];
}
}]
});
这将有效地在每页上创建 150 像素的左/右页边距,使表格居中。现在您只需弄清楚最适合您需求的边距大小即可。在此过程中,您可能还需要强制导出列的宽度:
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [{
extend: 'pdfHtml5',
text: 'PDF with image',
customize: function(doc) {
doc.content.forEach(function(item) {
if (item.table) {
// Set width for 3 columns
item.table.widths = [100, 40, '*']
}
});
}
}]
});
我正在迭代 content
数组,因为我们无法确定哪个索引保存 table
属性。上面只是将导出的三列布局设置为具有 100px
、40px
和“其余”宽度。如果您希望宽度根据内容进行调整,请使用'auto'
。请注意,如果您的 item.table.widths
与表中的列数不完全匹配,导出将会失败。
无论如何 - 通过定义 pageMargin
并可能对某些列的宽度进行一些细微的调整,您应该能够非常轻松地创建居中的 PDF。
关于jquery - 如何移动表格导出pdfhtml5数据表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35012599/
我正在使用 HTMLConverter 将 html 转换为 PDF 并尝试设置一些边距。 现有代码: ConverterProperties props = new ConverterPro
我正在使用 HTMLConverter 将 html 转换为 PDF 并尝试设置一些边距。 现有代码: ConverterProperties props = new ConverterPro
是否有 pdfHTML 支持的 CSS 样式列表?他们的网站说“它支持适用于 PDF 上下文的 HTML 5 和 CSS 3 规范的部分”,这是有道理的(例如,没有理由支持 CSS 动画)。 但是,我
我正在尝试使用 itext7.pdfhtml 将 html 字符串转换为 C# .Net 项目中的 pdf 文档。 当我运行此代码时: iText.Html2pdf.HtmlConverter.Con
我正在使用 iText 的 pdfHtml 从 HTML 生成 PDF,但我可以看到生成的 PDF 中的两个元素之间添加了很多空格。 请参阅下面的 HTML 和 PDF 下图中突出显示的部分显示了两行
我正在尝试使用 iText7.1.0 和 pdfHTML2.0.0 使用 this example 将 3 个 HTML 页面(全部具有相同的内容)导出为 PDF .出于某种原因,页面在页脚处存在格式
我正在尝试借助 iText 的方法将 html 转换为 pdf HtmlConverter.convertToPdf(htmlString, pdfDocument, converterProp);
我是一名优秀的程序员,十分优秀!