我正在尝试使用报告实验室创建指向 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()
我使用的是 Adobe Reader 11.0.10.32。当我单击矩形时,我收到一些警告,但在单击“允许”和"is"后,文件确实打开了。
关于python - Reportlab,相关文件链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26482749/