[英]html to pdf fit table on A4
即时通讯目前正在使用html-pdf ,它将我的表数据转换为pdf。
我的问题是表格内容与所需的A4
纸张重叠,因为pdf中有2列完全丢失,当我将format
更改为A3
它适合和工作。
我需要它适合A4
。 有任何想法吗 ?
const dlPdfResult = (result) => { return new Promise(function (resolve, reject) { optionsType = { format: 'A4', orientation: 'landscape', paginationOffset: 0, header: { 'height': '10mm', 'contents': `<div style=' font-family: sans-serif, Arial, Helvetica; font-size: 11px; text-align: left; width: 842px; overflow: hidden;'><div style='width: 10%; float:left;'></div><div style='width: 40%; float:left;padding: 0px 0px 0px 60px;'>Port2Port exports</div><div style='width: 40%; float:left; text-align: right;'>Logo</div><div style='width: 10%; float:left;'></div>` }, footer: { 'height': '10mm', 'contents': { first: '1', 2: '2', default: '<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>', last: 'Last Page' }, type: 'pdf', // allowed file types: png, jpeg, pdf quality: '75' } } tableForm = tableify(result) pdf.create(tableForm, optionsType).toFile('./test.pdf', function (err, res) { if (err) return reject(err) resolve(res) }) }) }
此时我唯一的解决方法就是替换我得到的表格结果并使用mm
添加样式并赋予其max-width
。
只有一个例子是:
tableForm = tableify(result)
strip = tableForm.replace(/<td/g, `<td style='max-width: 5mm;border: 1px solid #000;overflow: hidden;word-wrap: break-word;'`)
我这样做是为所有的td
和所有th
。
所以我的下一个替换看起来像:
var addStyleSpacingThString = strip.replace(/<th class="string">/g, `<th class='string' style='max-width: 5mm;text-align: left;'>`)
这是一个适合我所有内容的最后一件事我想提到的是我的表本身宽度为100%。
<table style=' width: 100%; heigth: auto;font-size: 11px;font-family: sans-serif, Arial, Helvetica; border-collapse: collapse;'>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.