1

首先,有两点:

  • 我知道,有很多类似的问题,但没有一个能帮助我找到解决问题的方法
  • 我是初学者 - 在编程的各个方面......

问题: 从 Web 服务接收字节数组,我需要在 Internet Explorer 9 中显示 PDF。以下代码在 Chrome 中运行,但在 IE9 中,我收到的只是一个深灰色面板,其中 PDF 是要放置的。

Ext.define('Ext.ux.form.DocumentFrame', {
extend: 'Ext.container.Container',
alias: 'widget.documentframe',
layout: 'hbox',
initComponent: function () {
    var me = this;
    var binaryData = me.value.DocumentData;
    var source = 'data:application/pdf;base64,' + (binaryData);

    Ext.applyIf(me, {
        items: [
                {
                xtype: 'box',
                itemId: 'panel-document-frame',
                width: 600,
                height: 600,
                autoEl: {
                    tag: 'object',
                    width: '100%',
                    height: '100%',
                    type: 'application/pdf',
                    data: source
                }
            }
        ]
    });
    me.callParent(arguments);
}
});
  • MIME 类型有问题吗?
  • 我必须对字节数组进行编码或解码吗?
  • 我在尝试在 IE9 上使用 PDF 的数据 URI时做错了吗?

我只是不明白为什么这在其他浏览器中有效,但在 IE9 中无效,尤其是在为存储的 PDF 文件提供路径时没有任何问题(即使在 IE9 中)。我通过像这样设置 autoEl 的数据参数来做到这一点:

data: 'content/files/Designer.pdf'

注意:通过在 IE9 中执行此操作,会出现一个 MessageBox:“此页面上的 Active X 控件可能不安全,无法与此页面的其他部分交互”。目前,我不在乎这个。

尝试从字节数组显示 PDF 时我错了吗?我真的坚持这一点,任何帮助将不胜感激!

先感谢您!

-编辑-

binaryData 可能是变量的错误名称或令人讨厌的名称。据我所知,这是一个字节数组,看起来像:

JVBERi0xLjQNCiXi48/TDQolDQold1BERjMgYnkgV1BDdWJlZCBHbWJIIFYzLjY1WzQwMjY1MzIxNl0gMzJiaXQgIHVuaWMgDQolDQolDQoxIDAgb2JqDTw8L1R5cGUvTWV0YWRhdGEvU3VidHlwZS9YTUwvTGVuZ3RoIDE0OTIgPj4NCnN0cmVhbQo8P3hwYWNrZXQgYmVnaW49Iu

…………

GQ5N2VlYjczYmVkZjczZWM5Pl0NCi9JbmZvIDIgMCBSDQo+Pg0Kc3RhcnR4cmVmDQo1NTgyDQolJUVPRg0K

毕竟,这是变量的完整值source

http://pastie.org/private/upqwjrkfwgmz1hxrx9vha

-edit2-

  • 我们使用的是 Adob​​e Reader 版本 11.0.3 (11.0.03.37)。
  • 在 IE9 中取消/激活 Adob​​ePDF-Plugin 没有效果 - 问题仍然存在
4

1 回答 1

0

正如 Colombo 和我之前提到的,IE 中的数据 uri 限制不允许使用 PDF。我认为,我们的方法类似于科伦坡在他的第二条评论中描述的解决方案。

在搜索了高低,阅读了大量资源并尝试了我能想象的任何东西之后,解决我的问题的唯一解决方案是将整个逻辑放入 ASP.NET 控制器中(感谢我的同事):

此代码正在运行,但处于“虚拟状态”!

字节数组位于“archiveDocument.Document.DocumentData”

public class PdfController : Controller
{
    [HttpGet]
    public ActionResult View(Guid id)
    {
        if (id == Guid.Empty || id == null)
            throw new ArgumentException("id null or emtpy", "id");

        using (var serviceClient = ServiceClient.GetAuthClient<ArchiveDocumentServiceClient, IArchiveDocumentService>())
        {
            var archiveDocument = serviceClient.GetById(id);
            if (archiveDocument == null)
                throw new ApplicationException("ArchiveDocument not found.");

            Response.Headers.Remove("Content-Disposition");
            Response.Headers.Add("Content-Disposition", "inline; filename=" + archiveDocument.Document.Name);

            return File(archiveDocument.Document.DocumentData, "application/pdf");
        }
    }
}

要将 pdf-Document 加载到 iframe 中,只需调用该函数(仍然是 dummy-code -> hardcoded guid):

xtype: 'box',
width: 600,
height: 900,
autoEl: {
    tag: 'iframe',
    scrolling: 'no',
    seamless: 'seamless',
    frameborder: 0,
    src: 'Pdf/View/031d2151-5315-4574-aeb5-8154693a928d'
}

我希望,这个解决方案可以帮助其他人。

感谢所有支持我的人!

于 2013-08-06T07:37:21.440 回答