2017-02-25 54 views
0

PDFTron XOD Viewer未在ASP.NET Core Core MVC 6 Razor View中加載XOD文件。檢查瀏覽器控制檯顯示錯誤:「瀏覽器鏈接:無法調用返回值回調:TypeError:無法獲取未定義或空引用的屬性」文件「。PDFTron XOD Viewer未在ASP.NET Core MVC 6上加載Razor View

瀏覽器顯示消息:「請」代替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剃刀視圖(文檔/ 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查看器或文件XOD。運行頁面和瀏覽器控制檯的解決方案屏幕截圖如下所示。 enter image description here

+0

對於最後一張圖片中「localhost/lib/webviewer.js」的404錯誤,「lib」文件夾實際上是託管路徑嗎?如果您在「lib」文件夾中說出圖像,您可以使用「/lib/myimage.png」加載到您的網頁嗎?如果你得到了404,那麼你的道路看起來是錯的。 – Ryan

+0

'lib'是一個託管文件夾。我已經把一個圖像放在'lib'文件夾中,並且能夠打開它。即使我能夠從瀏覽器打開'WebViewer.js'文件。 –

+1

我對「請」部分感到困惑。文字「請」出現?如果你得到的是WebViewer.js的404比我沒有看到它的任何代碼會被觸發。最後,從您發佈的代碼中看出,這是舊版WebViewer(從2013年左右開始)。請更新到WebViewer 2.2.2。 – Ryan

回答

0

按照Ryan的建議升級到WebViewer V2.2.2後解決。

相關問題