1

How is the right way to set Page Layout margin now? In borb 2.1.15 works properly and in examples is some like this too:

from borb.pdf import Document
from borb.pdf import Page
from borb.pdf import PageLayout
from borb.pdf import SingleColumnLayout

# create an empty PDF
doc: Document = Document()

# create an empty Page
page: Page = Page()
doc.add_page(page)

# set a PageLayout
layout: PageLayout = SingleColumnLayout(page, horizontal_margin=Decimal(50), vertical_margin=Decimal(50))

But in actual borb 2.1.16 this does not work.

I tried w= and h= but still not lucky.

Joris Schellekens
  • 8,483
  • 2
  • 23
  • 54
iggh
  • 11
  • 2

1 Answers1

1

disclaimer: I am the author of borb.

At some point, the signature of SingleColumnLayout changed to be more consistent with the other LayoutElement objects. You can either use SingleColumnLayout (which does not allow you to set these parameters), or you can use MultiColumnLayout (from which SingleColumnLayout inherits).

MultiColumnLayout has the following (default) parameters:

margin_bottom: Decimal = Decimal(84.2),
margin_left: Decimal = Decimal(59.5),
margin_right: Decimal = Decimal(59.5),
margin_top: Decimal = Decimal(84.2),

Your complete example would become:

from borb.pdf import Document
from borb.pdf import Page
from borb.pdf import PageLayout
from borb.pdf import MultiColumnLayout

# create an empty PDF
doc: Document = Document()

# create an empty Page
page: Page = Page()
doc.add_page(page)

# get Page width
w: typing.Optional[Decimal] = page.get_page_info().get_width()
assert w is not None

# set a PageLayout
layout: PageLayout = MultiColumnLayout(page, 
                                       column_widths=[w - Decimal(100)], 
                                       margin_top=Decimal(50), 
                                       margin_right=Decimal(50),
                                       margin_bottom=Decimal(50),
                                       margin_left=Decimal(50),
                                       )
Joris Schellekens
  • 8,483
  • 2
  • 23
  • 54