Closed lguerard closed 3 months ago
Actually I managed using page_layout._margin_left
etc. But then my tables are completely shifted and not covering the whole width of the page...
Setting the margin on the PageLayout
will shift all LayoutElement
objects (that are added to that PageLayout
). As far as I know, this is the desired behaviour.
I changed your code-snippet:
margin
to _margin
Page
, in the same Document
from decimal import Decimal
from borb.pdf import Document, Page, SingleColumnLayout, PageLayout, Paragraph, Image, PDF
def main():
# Create document
pdf = Document()
# Add page
page = Page()
pdf.add_page(page)
# create PageLayout
page_layout: PageLayout = SingleColumnLayout(page)
for i in [Decimal(0), Decimal(16), Decimal(32), Decimal(64)]:
page_layout._margin_left = i
page_layout._margin_right = i
page_layout._margin_bottom = i
page_layout._margin_top = i
# Add Paragraph
page_layout.add(Paragraph(f"padding set at {int(i)}"))
page_layout.add(
Image(
"https://images.unsplash.com/photo-1625604029887-45f9c2f7cbc9?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8",
width=Decimal(135),
height=Decimal(40),
)
)
with open("output.pdf", "wb") as out_file_handle:
PDF.dumps(out_file_handle, pdf)
if __name__ == "__main__":
main()
Which outputs the following PDF:
Thanks, I wasn't fully clear with what I wanted to achieve but as this is not a bug report, I've posted it to Stackoverflow.
Describe the bug Trying to change the margins of the
PageLayout
doesn't do anything.To Reproduce
Expected behaviour I was expecting the image to be placed more on the left with
i=0
Desktop (please complete the following information):