PDF中的相对文件链接(Reportlab) [英] Relative File Linking in PDF (Reportlab)

查看:318
本文介绍了PDF中的相对文件链接(Reportlab)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我特别在考虑类似excel电子表格的内容.

在ReportLab中,我可以添加

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

,它将成功链接到并与我生成的PDF所在的文件夹中打开linkedfile.pdf,但是文档中未提及除pdf以外的任何其他文件类型,显然xls://不起作用. >

有人知道这是否是PDF文件的限制,并且出于安全原因而被阻止?还是这仅仅是ReportLab不支持的功能?是否可以通过扩展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.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.当我单击矩形时,会收到一些警告,但是在单击允许"和是"后,文件确实会打开.

Is it possible to link to a relative external document that isn't a PDF file from a PDF document?

I'm specifically thinking something like an excel spreadsheet.

In ReportLab I can add something like

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

and it will successfully link to and open linkedfile.pdf in the same folder as my generated PDF, however the documentation doesn't mention any other file types other than pdf and obviously xls:// doesn't work.

Does anyone know if this is a limitation of PDF files and is prevented for security reasons? Or is this just something ReportLab doesn't support out the box? Could it be achieved by extending a ReportLab class?

Thanks.

解决方案

This is how I got relative links to files to work in 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()

I'm using Adobe Reader 11.0.10.32. When I click the rectangle I get a few warnings, but file does open up after clicking "Allow" and "Yes".

这篇关于PDF中的相对文件链接(Reportlab)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆