asciidoctor-pdf: Bad page rendering: margins are off the page
asciidoctor-pdf version: current master
test theme and test doc is in archive testdoc.zip
result pdf with mytest
theme
testpage.pdf
With the default built in theme everything is OK though.
If I do minor changes to the test document – margins are either ok or slighly wrong – I couldn’t figure out exactly what is the root cause of the issue.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 40 (40 by maintainers)
Commits related to this issue
- resolves #1170 prevent table alignment from modifying margins of subsequent pages — committed to mojavelinux/asciidoctor-pdf by mojavelinux 5 years ago
- resolves #1170 prevent table alignment from modifying margins of subsequent pages — committed to habamax/asciidoctor-pdf by mojavelinux 5 years ago
I now understand the root cause. We’ve already worked around it, but I want to document it here so the information isn’t lost.
If a bounding box is used around content that gets split across pages (which is what prawn-table does when position is set to center or right), and indent is used around subsequent content that also gets split across page, Prawn subtracts the indentation twice coming out of that function. That’s why the margin kept getting smaller and smaller. So it’s some sort of bad interaction between the bounding_box and indent functions.
Just tested it out – looks good for me
A fix is on the way.
I finally found a workaround.
The problem is caused by a bad interaction between a bounding box (for drawing) and the new page creation logic. Frankly, it’s a bit of a mess in Prawn and not easily fixable. Suffice to say, it’s not good to use a bounding box to restrict the width. It’s better to use margins (i.e., indent), which sidesteps the issue entirely. I had found this out when doing the TOC, but forgot about that rule.
Therefore, I will apply a patch to Prawn table that will use margin indenting instead of the bounding box to position the table.
Good news! I can isolate at least one page in the 15 page document where I can turn the problem on and off. That should be enough for me to see what is different about Prawn’s internal state at that point. All we need to do is figure out what state to reset and then we can at least fix the problem on our end.