python - 使用 Python 在 PDF 中放置垂直或旋转的文本

标签 python pdf fpdf pypdf

我目前正在使用 PyFPDF 生成 PDF。我还需要添加垂直/旋转文本。不幸的是,据我所知,PyPDF2 不直接支持它。有 FPDF for PHP 的解决方案。

是否可以使用 PyFPDF 或其他库从 Python 中插入垂直或旋转文本到 PDF 中?

最佳答案

我相信你可以用 PyMuPDF 做到这一点.我之前已经在模块中插入了文本,但没有旋转文本。 insertText 方法中有一个旋转参数,希望它对您有用。

可以按如下方式进行:

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 - 使用 Python 在 PDF 中放置垂直或旋转的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50306870/

相关文章:

java - 在java中将Html二进制图像转换为pdf

c# - 将高分辨率 PDF 转换为低分辨率 PDF 文件 C#

php - 有没有办法让 FPDF/FPDI 或 Zend_Pdf 支持解析大于 1.4 的 PDF?

php - 单元格内的背景颜色在 fpdf 中没有改变

php - html2pdf 无法识别空格并且无法添加边距

python - 服务器 : I moved from python 2. 7 到 3.5 上的 django 应用程序和 apache2 找不到 django

Python-pandas - 日期时间索引 : What is the mosty pythonic strategy to analyse rolling with steps? (例如每天的某些时间)

xml - XSL-FO 页码 2a、2b

python - Jupyter 笔记本信号仅在主线程中有效

python - 无法在 python 中导入自定义 DLL