0

PDFTron XOD 查看器未在 ASP.NET Core MVC 6 Razor 视图上加载 XOD 文件。检查浏览器控制台显示错误:“浏览器链接:无法调用返回值回调:TypeError:无法获取未定义或空引用的属性'文件'”。

浏览器显示消息:“请”代替 WebViewer 控件。我看到这来自代码部分的 PDFTron WebViewer.js 文件,如下所示:

else {
            var supportErrorArray = new Array();
            supportErrorArray.push("Please");
            if (allowHTML5) {
                supportErrorArray.push("use an HTML5 compatible browser");
                if (allowSilverlight || allowFlash) {
                    supportErrorArray.push("or");
                }

me.selectedType is noneWebVeiwer.js我在WebViewer.js文件中发出警报时开始。PDFTron XODViewer 不支持 ASP.NET Core MVC 6 吗?

我使用一种解决方法通过检查来更正WebViewer.js脚本:

if(me.selectedType == null)
{
     if (this.options.html5Options) {
                $.extend(this.options, this.options.html5Options);
            }
            me._createHTML5();
}

MVC 6 Razor View (Document/Index.cshtml) 标记如下:-

@model XODViewer.Models.Document

@{
    ViewBag.Title = "Document";
}

<script src="@Url.Content("~/lib/jquery/dist/jquery.js")"></script>
<script src="@Url.Content("~/lib/WebViewer.js")"></script>
<style>
    #viewer {
        width: 1024px;
        height: 600px;
    }
</style>

<script>
    $(function () {
            var docName = '@Html.Raw(Model.DocumentName)';
            var viewerElement = document.getElementById('viewer');
            var myWebViewer = new PDFTron.WebViewer({
                path: '../../lib',
                type: '../../lib/html5',
                documentType: "xod",
                initialDoc: "../../XodFiles/GettingStarted.xod",
                config: '',
                streaming: false,
                enableAnnotations: false,
                enableOfflineMode: false,
                enableReadOnlyMode: true
            }, viewerElement);
        });
</script>

@Html.Raw(ViewBag.Message)

<div id="viewer" style="padding:10px; word-wrap:break-word;">
</div>

ASP.NET Core MVC 6 解决方案如随附的屏幕截图所示。 在此处输入图像描述

我已经为 XOD 设置了如下内容类型:-

// Set up custom content types -associating file extension to MIME type
            var provider = new FileExtensionContentTypeProvider();
            // Add new mappings
            provider.Mappings[".json"] = "application/json";
            provider.Mappings[".woff"] = "application/font-woff";
            provider.Mappings[".res"] = "text/plain";
            provider.Mappings[".nmf"] = "text/plain";
            provider.Mappings[".pexe"] = "text/plain";
            provider.Mappings[".mem"] = "text/plain";
            provider.Mappings[".brotli"] = "text/plain";
            provider.Mappings[".xod"] = "application/vnd.ms-xpsdocument";
            // Remove MP4 videos.
            //provider.Mappings.Remove(".mp4");

            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(
                    Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", "XodFiles")),
                RequestPath = new PathString("/XodFiles"),
                ContentTypeProvider = provider
            });

最后,在运行解决方案时,不会显示 XOD Viewer 或 XOD 文档。运行页面和浏览器控制台的解决方案截图如下所示。 在此处输入图像描述

4

1 回答 1

0

按照 Ryan 的建议升级到 WebViewer V2.2.2 后解决。

于 2017-03-02T15:26:23.870 回答