more rotation examples / advices for text rotation and positioning #967
-
Hi. I am trying to migrate to python an old php script which used fpdf to produce a multipage pdf,. As I found a similar closed issue related to text roataion, I shared an example code there: But I am not being able to achieve what I want. Thanks a lot in advance |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Welcome to fpdf2, @abubelinha! allow me to invite you to a little thought experiment: If you remove the rotation context from your example, where would you expect the cell text to appear on the page? Before thinking about it in this systematic way, you seem to have expected the text to be magically teleported to the pivot point.
Alternatively, for placing elements in arbitrary positions on the page, you might consider using |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot @gmischler With your great suggestions I could now reuse As I asked for more examples, here I post both methods for future reference (suggestions welcome to improve them): from fpdf import FPDF
pdf = FPDF(orientation="P", unit="mm", format="A4")
pdf.add_page()
pdf.set_font("times")
a,x,y=90,10,295 # left margin banner using .text():
with pdf.rotation(angle=a, x=x, y=y):
banner = pdf.text(x=x, y=y,
text= "This text should start at left bottom of the page and continue upwards through its left margin"
)
print(banner)
a,x,y=270,208,5 # right margin banner using .set_xy(x,y) and .cell()
pdf.set_auto_page_break(False)
pdf.set_xy(x,y)
pdf.set_line_width(0.25)
with pdf.rotation(angle=a, x=x, y=y):
pdf.cell(
text= "This text should start at right top of the page and continue downwards through its right margin",
border=1,
h=10, # box height 10 mm
# w=0 # I guess in rotation context this does not work as expected:
# how can I extend text box downwards, far beyond text end, near to page bottom?
)
pdf.output("fpdf-lateral-banner-text.pdf") Two more doubts:
Thanks a lot again!! |
Beta Was this translation helpful? Give feedback.
Welcome to fpdf2, @abubelinha!
allow me to invite you to a little thought experiment:
If you remove the rotation context from your example, where would you expect the cell text to appear on the page?
And now that you have your text somewhere, imagine it to slowly rotate around a pivot point at the very bottom of the page.
Which way will it move, and where will it end up?
Before thinking about it in this systematic way, you seem to have expected the text to be magically teleported to the pivot point.
That is evidently not how it works.
.cell()
always places the text below and to the right of the current page position. The docstring forrotation()
explains that this current position will no…