2014-01-24 53 views
0

是否可以从PDF文档链接到不是PDF文件的相对外部文档?PDF中的相对文件链接(Reportlab)

我特别想像一个excel电子表格。

在ReportLab的,我可以添加类似

Elements.append(Paragraph("<a href=\"pdf://linkedfile.pdf\">File</a>",style)) 

,它会成功连接并打开linkedfile.pdf在同一文件夹作为我的生成PDF,但该文件没有提到其他任何其他文件类型比PDF和显然xls://不起作用。

有谁知道这是否是PDF文件的限制,并出于安全原因而被阻止?或者,这仅仅是ReportLab不支持的框?可以通过扩展ReportLab类来实现吗?

谢谢。

回答

0

您是否尝试过使用file://而不是pdf://?我目前无法测试,可能取决于您使用的pdf-viewer/file-manager。

0

这是怎么弄到的文件相对链接在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.xls is in the same directory as the pdf 
c.linkURL(r'example.xls', (inch, inch, 2*inch, 2*inch), relative=1) 
c.save() 

我使用ADOBE READER 11.0.10.32。当我点击矩形时,我收到一些警告,但点击“允许”和“是”后文件确实打开。