Place a vertical or rotated text in a PDF with Python

女生的网名这么多〃 提交于 2019-12-23 23:25:11

问题


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.

Is there a way to insert vertical or rotated text in a PDF from Python, either with PyFPDF or with another library?


回答1:


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()


来源:https://stackoverflow.com/questions/50306870/place-a-vertical-or-rotated-text-in-a-pdf-with-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!