【问题标题】:Place a vertical or rotated text in a PDF with Python使用 Python 在 PDF 中放置垂直或旋转文本
【发布时间】:2018-10-22 17:30:45
【问题描述】:

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

有没有办法在 Python 中的 PDF 中插入垂直或旋转文本,无论是使用 PyFPDF 还是使用其他库?

【问题讨论】:

    标签: python pdf fpdf pypdf


    【解决方案1】:

    我相信您可以通过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()
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-03
    • 2013-06-20
    • 2015-10-31
    • 1970-01-01
    相关资源
    最近更新 更多