from borb.pdf.pdf import PDF from borb.pdf.page.page import Page from borb.pdf.canvas.layout.page_layout.multi_column_layout import SingleColumnLayout from borb.pdf.canvas.layout.page_layout.page_layout import PageLayout from borb.pdf.canvas.font.simple_font.true_type_font import TrueTypeFont from borb.pdf.canvas.font.font import Font from borb.pdf.canvas.color.color import HexColor, X11Color from decimal import Decimal from borb.pdf.canvas.layout.text.paragraph import Paragraph from borb.pdf.canvas.layout.layout_element import LayoutElement from borb.pdf.canvas.geometry.rectangle import Rectangle with open("Planner.pdf", "rb") as in_file_handle: doc = PDF.loads(in_file_handle) # Get PDF Page page: Page = doc.get_page(0) # set a PageLayout #layout: PageLayout = SingleColumnLayout(page) # construct the Font object font_path: Path = Path(__file__).parent / "Ubuntu-Light.ttf" custom_font: Font = TrueTypeFont.true_type_font_from_file(font_path) ''' # add a Paragraph layout.add( Paragraph( "Hello World!\nHi me", font=custom_font, font_size=Decimal(40), respect_newlines_in_text=True, font_color=HexColor("#666666"), padding_top=Decimal(10), padding_right=Decimal(10), padding_bottom=Decimal(10), padding_left=Decimal(10))) ''' r: Rectangle = Rectangle( Decimal(59), # x: 0 + page_margin Decimal(848 - 84 - 100), # y: page_height - page_margin - height_of_textbox Decimal(595 - 59 * 2), # width: page_width - 2 * page_margin Decimal(100), # height ) Paragraph("Hello World!", font_color=HexColor("#666666")).layout(page, r) with open("output.pdf", "wb") as pdf_file_handle: PDF.dumps(pdf_file_handle, doc)