当一个表增加行时,如何调整JSPDF文档中的元素,避免表或文本垂直重叠?
我是React和JavaScript的初学者。我一直在尝试找到解决问题的解决方案,但似乎找不到特定的解决方案。我正在使用“ JSPDF”和它的插件“ JSPDF-autotable”生成.pdf文档(客户发票)。
它都会生成确定的,给出每个元素(文本,图像,表),它是xy启动在JavaScript代码中的坐标。我有2张桌子。表A和表B。两者都垂直将一个位于另一个位置。当“表A”增加时,它是一段时间开始重叠“表B”的时间。表B具有固定数量的行。
如何避免“表A重叠”表B”,并在“表A”增加时将表A“动态'向下'移动'向下移动'表A的所有内容?
示例:
const generatePDF = () => {
const unit = "pt";
const size = "A4"
const orientation = "portrait";
const doc = new jsPDF(orientation, unit, size);
let contentA = {
head: [["Item", "Quantity", "Price", "Item Total"]],
body: [
['Water Bottle A', '1', '8.99', '8.99'],
['Water Bottle B', '1', '8.99', '8.99'],
['Water Bottle C', '1', '8.99', '8.99'],
['Water Bottle D', '1', '8.99', '8.99'],
],
foot: [['', '', 'Total:', '35.96']],
margin: 40,
tableLineWidth: 0.5,
tableLineColor: "black",
tableWidth: 'auto',
startY: 100,
theme: 'striped',
pageBreak: 'auto',
}
let contentB = {
head: [["Subtotal", "$35.96"]],
body: [
['Taxes', '$4.49'],
['Payment Method:', 'Cash'],
],
foot: [['Total:', '35.96']],
margin: 40,
tableLineWidth: 0.5,
tableLineColor: "black",
tableWidth: 'auto',
startY: 150,
theme: 'striped',
pageBreak: 'auto',
}
doc.autoTable(contentA)
doc.autoTable(contentB)
doc.text('Thank you for your purchase!', 150, 800);
doc.save("my-report-document.pdf")
}
这里的所有行都是静态的(在我的应用程序中,我会通过一系列对象循环并盖上行,但是此示例解释了我的问题)将与“ contentb”表重叠。
“ starty”属性是目前唯一建立每个表的启动'y坐标的属性。我不介意“表A”下面的内容分为第二页,我只想摆脱垂直重叠。
任何帮助将不胜感激。
I'm a beginner in React and Javascript. I've been trying to find a solution to my problem but can't seem to find the specific solution. I'm generating a .pdf document (customer invoice) using "jsPdf" and it's plugin "jspdf-autoTable".
It all generates OK giving each element (text, image, table) it's XY starting coordinates in the javascript code. I have 2 tables. Table A and Table B. Both are positioned one next to the other vertically. When "table A" increases it's rows, there comes a time when it starts to overlap "table B". Table B has fixed number of rows.
How can I avoid "table A" overlapping "table B", and have ALL the content below "table A" move dynamically 'downward' when "table A" increases?
Example:
const generatePDF = () => {
const unit = "pt";
const size = "A4"
const orientation = "portrait";
const doc = new jsPDF(orientation, unit, size);
let contentA = {
head: [["Item", "Quantity", "Price", "Item Total"]],
body: [
['Water Bottle A', '1', '8.99', '8.99'],
['Water Bottle B', '1', '8.99', '8.99'],
['Water Bottle C', '1', '8.99', '8.99'],
['Water Bottle D', '1', '8.99', '8.99'],
],
foot: [['', '', 'Total:', '35.96']],
margin: 40,
tableLineWidth: 0.5,
tableLineColor: "black",
tableWidth: 'auto',
startY: 100,
theme: 'striped',
pageBreak: 'auto',
}
let contentB = {
head: [["Subtotal", "$35.96"]],
body: [
['Taxes', '$4.49'],
['Payment Method:', 'Cash'],
],
foot: [['Total:', '35.96']],
margin: 40,
tableLineWidth: 0.5,
tableLineColor: "black",
tableWidth: 'auto',
startY: 150,
theme: 'striped',
pageBreak: 'auto',
}
doc.autoTable(contentA)
doc.autoTable(contentB)
doc.text('Thank you for your purchase!', 150, 800);
doc.save("my-report-document.pdf")
}
All rows here are static (in my app Im looping through a cart array of objects and gnerating the rows, but this example explains my problem), if I where to add 30 more rows to body property of "contentA", the table would overlap with "contentB" table.
The "startY" property is the only property right now establishing the starting 'Y' coordinate of each table. I dont mind if the content below "table A" breaks into a 2nd page, I just want to get rid of the vertical overlapping.
Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用:
这样:
you can used :
like this :