使用Python将垂直或旋转文本放置在PDF中 [英] Place a vertical or rotated text in a PDF with Python
本文介绍了使用Python将垂直或旋转文本放置在PDF中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用PyFPDF生成PDF.我还需要添加垂直/旋转文本.不幸的是,据我所知,PyPDF不直接支持它.有适用于PHP的FPDF解决方案.
I'm currently generating a PDF with PyFPDF. I also need to add a vertical/rotated text. Unfortunately, it's not directly supported in PyPDF as far as I see. There are solutions for FPDF for PHP.
是否可以通过PyFPDF或其他库在Python的PDF中插入垂直或旋转文本?
推荐答案
我相信您可以使用 PyMuPDF .我之前在模块中插入了文本,但没有旋转文本. insertText
方法中有一个rotate参数,因此希望它对您有用.
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.
可以执行以下操作:
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()
这篇关于使用Python将垂直或旋转文本放置在PDF中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文