Python Reportlab,相对文件链接

Python Reportlab,相对文件链接,python,reportlab,Python,Reportlab,我正在尝试使用report lab创建一个pdf格式的xlsx文档的相对文件链接。 这里也提出了同样的问题,我无法发表评论 编辑:一个人回答了,建议使用file://,但这并不相对链接,而是在单击时转到根文件目录。(至少在chrome和OS X预览版中,它至少需要在chrome中工作)我对这个问题给出了相同的答案: 这就是我如何获得在reportlab中工作的文件的相对链接: from reportlab.pdfgen import canvas from reportlab.lib.units

我正在尝试使用report lab创建一个pdf格式的xlsx文档的相对文件链接。 这里也提出了同样的问题,我无法发表评论


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

我对这个问题给出了相同的答案:

这就是我如何获得在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()

我使用的是AdobeReader11.0.10.32。当我单击矩形时,会收到一些警告,但在单击“允许”和“是”后,文件确实会打开。

“无人应答”。这个问题有答案,但你没有提到这是否有效。更新了我的问题。