jorisschellekens / borb

borb is a library for reading, creating and manipulating PDF files in python.
https://borbpdf.com/
Other
3.37k stars 148 forks source link

Avoid blank lines between paragraphs / _get_margin_between_elements #197

Closed hemabe closed 7 months ago

hemabe commented 7 months ago

Hi Joris,

I asked this a few months before and the problem was solved. But after the latest update I ran into the same problem again. I have a MultiColumnLayout and I add every line as a Paragraph to the Layout, so I can modify the line (like adding a colored border). But now I have a margin between every line again and I don't know to fix this. I would like to have a margin of Decimal(0).

In your latest answer (https://github.com/jorisschellekens/borb/issues/152#issuecomment-1430794062) you suggested that I create my own custom LayoutManager and overwrite _get_margin_between_elements. I did this, it worked perfect. Now I'm missing this function.

Any idea how I can fix this problem again?

Thanks for your great work, Hermann Behrens

jorisschellekens commented 7 months ago

It's called _calculate_leading_between.

Kind regards, Joris Schellekens

hemabe commented 7 months ago

Hi Joris, I tried this:

class MyLayoutManager(MultiColumnLayout):
    def _calculate_leading_between(e0: LayoutElement, e1: LayoutElement) -> Decimal:
        return Decimal(0)

but this is not working. Is it because the function is a staticmethod now?

Thanks, Hermann Behrens

jorisschellekens commented 7 months ago

That may be the problem. I'm not sure.

I think the best thing for you to do is to simply copy the code in MultiColumnLayout (rather than subclassing it) to make your own PageLayout.

That way your code doesn't depend on the private methods staying the same.

Kind regards, Joris Schellekens