python - Reportlab,相关文件链接

标签 python reportlab

我正在尝试使用报告实验室创建指向 pdf 中的 xlsx 文档的相对文件链接。 这里提出了同样的问题Relative File Linking in PDF (Reportlab) ,我无法发表评论。

编辑:有人回答,建议使用 file://,但这并不相对链接,而是单击时转到根文件目录。 (至少在chrome和OS X Preview中,要求至少在chrome中工作)

最佳答案

我对此问题发布了相同的答案:Relative File Linking in PDF (Reportlab)

这就是我如何获得要在reportlab中工作的文件的相对链接:

from reportlab.pdfgen import canvas
from reportlab.lib.units import inch

# Create a canvas and add a rectangle to it
c = canvas.Canvas("link_test.pdf")
c.translate(inch, 9 * inch)
c.rect(inch,inch,1*inch,1*inch, fill=1)

# example.xlsx is in the same directory as the pdf
c.linkURL(r'example.xlsx', (inch, inch, 2*inch, 2*inch), relative=1)
c.save()

我使用的是 Adob​​e Reader 11.0.10.32。当我单击矩形时,我收到一些警告,但在单击“允许”和"is"后,文件确实打开了。

关于python - Reportlab,相关文件链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26482749/

相关文章:

python - 为什么 len 在 DataFrame 上比在底层 numpy 数组上效率高得多?

python - 从数据帧中包含的列表动态地将列添加到 pandas 数据帧

python - 在 matplotlib.pyplot 中绘制日期的线性回归

python - 如何正确检查滚动结束?

python - 在 Python 中为现有 PDF 创建大纲/目录

python - 您如何在 Geraldo Reports 中生成/创建表格?

Python-报告实验室 : Error using custom font

python -/usr/bin/python : No module named pip

python - 使第二列的数据保留在第二列

python - 我如何找出我正在运行的 reportlab 版本?