I am new to this library. I want to create "newspaper lookalike" page with this library.
I want to add headline, lead, text and image to the pdf file. Text is very long so i want to use MultiColumnLayout. I also want to set up the margins and spacing between the columns. Are there any explanations, code snippets for this? When every I copy/paste the code that I find on the internet, I get some kind of error, like code is updated.
I have this code, but I do not have a clue how to add text, margins, column spacing or even image:
from borb.pdf import Document
from borb.pdf import Page
from borb.pdf import PageLayout
from borb.pdf import MultiColumnLayout
# create an empty PDF
Document = Document()
# create an empty Page
Page = Page()
doc.add_page(page)
# set a PageLayout
PageLayout = MultiColumnLayout(page,
column_widths=[w - Decimal(100)],
margin_top=Decimal(50),
margin_right=Decimal(50),
margin_bottom=Decimal(50),
margin_left=Decimal(50),
)
disclaimer: I am the author of
borbLet's go over your code
The imports are fine for now. You will need more imports if you want to add content, but we'll get to that.
Next we create an empty
Document. TheDocumentclass represents a PDF. It would be better if you did not name your variables after classes.One thing I would also do is to add type hints. But that's completely optional.
Next we add an empty
Pageto theDocumentwe made. Again, don't name your variables after classes.Next we use a
PageLayout.MultiColumnLayoutis an instance ofPageLayoutthat will split aPageinto several columns, and flow content from one column to the next when needed.Again, do not name variables after existing classes.
Now we can add some content!
And finally we can store the
DocumentOr, the complete example in 1 snippet:
which yields the following PDF:
If you need more examples, check out the examples repository.