我目前使用的是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)
})
})
}
发布于 2019-06-18 19:10:25
目前,我唯一的解决办法是替换我得到的表结果,并使用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;'>
https://stackoverflow.com/questions/56647049
复制相似问题