I'm currently generating a PDF with PyFPDF. I also need to add a vertical/rotated text. Unfortunately, it's not directly supported in PyPDF2 as far as I see. There are solutions for FPDF for PHP.
Is there a way to insert vertical or rotated text in a PDF from Python, either with PyFPDF or with another library?
I believe you can do so with PyMuPDF. I've inserted text with the module before but not rotated text. There is a rotate parameter in the insertText
method so hopefully it will work for you.
It can be done as follows:
import fitz
doc = fitz.open(filename)
page = doc[0]
point = fitz.Point(x, y) # in PDF units (1 / 72 of an inch)
page.insertText(
point,
text="Hello World",
fontsize=8,
fontname="Helvetica", # Use a PDF Base 14 Fonts, else check documentation
color=(0, 0, 0),
rotate=90
)
doc.save(filename, incremental=True)
doc.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With