jorisschellekens / borb

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

Avoid blank lines between paragraphs / fixed_paragraph_spacing missing #152

Closed hemabe closed 1 year ago

hemabe commented 1 year ago

Hi,

I want to add many one-line-paragraphs to a MultiColumnLayout which works nice, but between the lines are blank lines.

How to remove these blank lines? In an older version of borb I used fixed_paragraph_spacing, but this option is not available anymore.

Greetings ...

jorisschellekens commented 1 year ago

Hi there,

I think that functionality was moved to MultiColumnLayout, it makes more sense to me that the PageLayout gets to decide what the space between LayoutElement objects is.

You can find the functionality in _get_margin_between_elements.

If you want to change it, simply create your own PageLayout (for instance by subclassing MultiColumnLayout) and change that method.

Here is an example of such a modified PageLayout (although you can certainly make a more intelligent version)

from borb.pdf.canvas.layout.page_layout.multi_column_layout import MultiColumnLayout
from borb.pdf.canvas.layout.layout_element import LayoutElement

class MyLayoutManager(MultiColumnLayout):

  def _get_margin_between_elements(self, previous_element: LayoutElement, element: LayoutElement) -> Decimal:
    if previous_element is None:
      return Decimal(0)
    return Decimal(1)

Kind regards, Joris Schellekens

hemabe commented 1 year ago

Hi,

this works beautifully. Thank you very much.