Textblock example¶
This example shows the functionality of the TextBlock element.
It creates a sample cheque to demonstrate the positioning of the elements on the page.
The code¶
from pylatex import (
Document,
HorizontalSpace,
HugeText,
MediumText,
MiniPage,
SmallText,
TextBlock,
VerticalSpace,
)
from pylatex.utils import bold
geometry_options = {"margin": "0.5in"}
doc = Document(indent=False, geometry_options=geometry_options)
doc.change_length("\TPHorizModule", "1mm")
doc.change_length("\TPVertModule", "1mm")
with doc.create(MiniPage(width=r"\textwidth")) as page:
with page.create(TextBlock(100, 0, 0)):
page.append("**** Ten Thousand Dollars")
with page.create(TextBlock(100, 0, 30)):
page.append("COMPANY NAME")
page.append("\nSTREET, ADDRESS")
page.append("\nCITY, POSTAL CODE")
with page.create(TextBlock(100, 150, 40)):
page.append(HugeText(bold("VOID")))
with page.create(TextBlock(80, 150, 0)):
page.append("DATE")
page.append(MediumText(bold("2016 06 07\n")))
page.append(HorizontalSpace("10mm"))
page.append(SmallText("Y/A M/M D/J"))
with page.create(TextBlock(70, 150, 30)):
page.append(MediumText(bold("$***** 10,000.00")))
page.append(VerticalSpace("100mm"))
doc.generate_pdf("textblock", clean_tex=False)
The generated files¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | \documentclass{article}% \usepackage[T1]{fontenc}% \usepackage[utf8]{inputenc}% \usepackage{lmodern}% \usepackage{textcomp}% \usepackage{lastpage}% \usepackage{parskip}% \usepackage{geometry}% \geometry{margin=0.5in}% \usepackage{ragged2e}% \usepackage{textpos}% % \setlength{\TPHorizModule}{1mm}% \setlength{\TPVertModule}{1mm}% % \begin{document}% \normalsize% \begin{minipage}{\textwidth}% \begin{textblock}{100}% (0, 0)% \noindent% **** Ten Thousand Dollars% \end{textblock}% \begin{textblock}{100}% (0, 30)% \noindent% COMPANY NAME% \newline% STREET, ADDRESS% \newline% CITY, POSTAL CODE% \end{textblock}% \begin{textblock}{100}% (150, 40)% \noindent% \begin{Huge}% \textbf{VOID}% \end{Huge}% \end{textblock}% \begin{textblock}{80}% (150, 0)% \noindent% DATE% \begin{large}% \textbf{2016 06 07\newline% }% \end{large}% \hspace*{10mm}% \begin{small}% Y/A M/M D/J% \end{small}% \end{textblock}% \begin{textblock}{70}% (150, 30)% \noindent% \begin{large}% \textbf{\$***** 10,000.00}% \end{large}% \end{textblock}% \vspace*{100mm}% \end{minipage}% \end{document} |
textblock.pdf