pdfjs
pdfjs copied to clipboard
Putting a table within a table causes cell misalignment on page breaks
I have a project requiring nesting tables within the cells of another table. In general it works very well, but the alignment shifts for the first row after a page break. I've come up with a contrived example by making the following edits on http://pdfjs.rkusa.st/
- Change lines 61-64 to: var article = tr.cell().table({widths: [null], borderWidth: 1}).row().cell(desc)
- Add another row on line 74: addRow(6, 'Article G', lorem, 50)
The added row, which is the first row after the page break, will have strange borders. This shows that the cell is not being aligned correctly. If you look closely you will see that the top padding is removed from the Lorem text as well (no longer aligned with the price). Screenshot here: https://imgur.com/a/3OIxzoX. Any thoughts on what might cause this?
Thanks for the report and providing an example to reproduce it! This is definitely something that needs to be fixed and I'll look into it eventually (but cannot say when, yet)
Hi, any updates on this issue? I might be experiencing a similar case caused by the same issue. As you can see on these screenshots, page breaks can sometimes cause unwanted row shifts:
https://imgur.com/a/OQYeXSB
Similar to @tdodgehdai , This is occurring on our project requiring nesting tables within the cells of another table and is kinda tricky to debug. Do we have a way of knowing when a page break will happen perhaps?
It is not very high on my list, so I don't expect a fix any time soon.
Do we have a way of knowing when a page break will happen perhaps?
No, and even if you'd know it, the way pdfjs
is built (to directly write everything it receives into the PDF right away and try figure out the layout on the way), there is no way for you to change the behaviour on page break.
The best option for now is to avoid table/cell nesting. If you like, feel free to post a reduced version of your code, maybe I can help by suggesting changes to reduce it to a single table.