【问题标题】:Relative File Linking in PDF (Reportlab)PDF 中的相对文件链接 (Reportlab)
【发布时间】:2014-02-15 08:55:43
【问题描述】:

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

我正在特别考虑类似 Excel 电子表格的东西。

在 ReportLab 中,我可以添加类似

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

它会成功链接并打开与我生成的 PDF 相同的文件夹中的linkedfile.pdf,但是文档没有提到除 pdf 之外的任何其他文件类型,显然 xls:// 不起作用。

有谁知道这是否是 PDF 文件的限制并且出于安全原因而被阻止?或者这只是 ReportLab 不支持开箱即用的东西?是否可以通过扩展 ReportLab 类来实现?

谢谢。

【问题讨论】:

    标签: python pdf pdf-generation reportlab


    【解决方案1】:

    这就是我获得文件的相对链接以在 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()
    

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

    【讨论】:

    • 我在documentation 上找不到linkURL。这个例子对我不起作用。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 2022-06-15
      • 2018-12-21
      • 2011-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多