【问题标题】:Embed PDF In Dexterity File View在 Dexterity 文件视图中嵌入 PDF
【发布时间】:2014-08-07 15:59:03
【问题描述】:

我想要一个快速简单(依赖于插件)的 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 的说明进行操作,它适用于原型文件视图,但似乎不适用于敏捷文件视图。

我猜关键部分在<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>
...

我也尝试过&lt;object ... attributes="data context/absoulte_url;"&lt;embed ... attributes="src context/absolute_url",但都不起作用。它只显示一个灰色背景的块。请参阅图片以供参考。

有什么建议吗?

【问题讨论】:

  • 我也遇到了同样的问题,我尝试过在Dexterity Doc 中看到类似的东西,但是用problem to load PDF 显示框灰色,我认为@Mathias 可以帮助我们。

标签: plone dexterity


【解决方案1】:

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

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

同样适用于指向 pdf 文件的链接,带有文件名的下载对话框会显示,而没有 pdf 文件则在 Firefox 中呈现。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多