在Dexterity文件视图中嵌入PDF

时间:2014-02-07 08:16:51

标签: plone dexterity

我想要一个快速简便的(依赖插件的)PDF嵌入式视图,而不仅仅是文件项的下载链接。

我的自定义文件架构如下所示:

class IBulletin(form.Schema):
    ...

    form.primary('file')
    file = NamedBlobFile(
        title=_(u"File"),
        required=False,
    )

class Bulletin(Item):
    grok.implements(IBulletin, IFile)

我遵循http://www.kcsts.co.uk/blog/embedded-pdf-in-file-view-with-plone的说明,它适用于Archetypes文件视图,但似乎不适用于敏捷文件视图。

我猜关键部分在<object ...><embed ...>之内。我对模板的试用看起来如下:

<metal:content-core define-macro="content-core"
   tal:define="content_type context/file/contentType|nothing;
               location string:${context/absolute_url}/@@download/file/${context/file/filename};
               v python:context.restrictedTraverse('contenttype_utils');">

<object class="viewembededfile" type="application/pdf" data=""
 tal:condition="python:content_type.endswith('pdf')"
 tal:attributes="data location; width string:100%; height string:900">
  <a href="" tal:attributes="href location">Please click here to download the PDF.</a>
  <embed src="" class="viewembededfile" type="application/pdf"
   tal:attributes="src location">
  </embed>
</object>
...

我还尝试了<object ... attributes="data context/absoulte_url;"<embed ... attributes="src context/absolute_url",但无效。它仅显示具有灰色背景的块。请参阅图片以供参考。

enter image description here

有什么建议吗?

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,经过一些反复试验,我发现如果我不在pdf文件的位置末尾包含文件名,那么至少Firefox会开始显示嵌入式pdf

<object type="application/pdf"
    tal:attributes="data string:${context/absolute_url}/@@download/file">
</object>

同样适用于pdf文件的链接,显示文件名下载对话框,并且不在Firefox中呈现pdf文件。