将超链接插入到用 pisa 生成的 pdf 中

Inserting hyperlinks into pdf generated with pisa

目前我正在从 django/python 中的 html 模板生成 pdf。

这是我认为的相关片段

result = StringIO.StringIO()
html = render_to_string(template='some_ref/pdf.html', { dictionary passed to template},)
pdf = pisa.pisaDocument(StringIO.StringIO(html), dest=result) 
return HttpResponse(result.getvalue(), content_type='application/pdf')  

我的模板是一个 html 文件,我想在其中插入一个 hyperlink。像

 <td style="padding-left: 5px;">
     <a href="/something_here/?referral_type={{ template_variable }}">{{ some_other_variable }}</a>
 </td>

实际上,pdf 生成的很好,模板变量被正确传递并显示在 pdf 中。 a 标签内的内容以蓝色突出显示并带有下划线,就好像您可以点击它一样,但是当我尝试点击它时,link 没有被跟随。我以前看过带有可点击 links 的 pdf,所以我相信它可以完成。

有什么方法可以让我使用 pisa 在我的 pdf 上制作可点击的 hyperlinks 吗?

它适用于完整的 url:http 协议和域

<a href="http://127.0.0.1:8000/something_here/?referral_type={{ template_variable }}">{{ some_other_variable }}</a>