PDFTron XOD Viewer未加载到ASP.NET Core MVC 6 Razor View

时间:2017-02-25 15:38:06

标签: asp.net-core asp.net-core-mvc pdftron

PDFTron XOD Viewer无法在ASP.NET Core MVC 6 Razor View上加载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 none文件中发出提醒时,来自WebVeiwer.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解决方案如附带的屏幕截图所示。 enter image description here

我已经为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文档。运行页面和浏览器控制台的解决方案的屏幕截图如下所示。 enter image description here

1 个答案:

答案 0 :(得分:0)

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