干净简便的HTML5文档查看器——GroupDocs.Viewer

    GroupDocs.Viewer是一个在线文档查看器,无论是否安装了建立某个文档的软件,GroupDocs.Viewer都容许使用浏览器查看这个文档。GroupDocs.Viewer支持查看多种文件文档(DOC、DOCX、TXT、RTF、ODT),演示文档(PPT、PPTX),电子表格(XLS、XLSX),便携式文件(PDF)以及图像文件(JPG、BMP、TIFF)。javascript

点击下载GroupDocs.Viewer试用版java


    咱们这个项目就是探寻一款干净简便的HTML5文档查看器,关于这方面的产品是不少的,因此这个探索过程是很繁琐的,不少人的第一想法就是是使用Google Docs Viewer或相似的解决方案,但因为应用程序将在客户端Intranet上运行,申请和文件都不容许暴露在互联网上,因此这是不可行的。web

 通过探讨,咱们制定了如下标准:浏览器

  • 适用于Windows Server和.NET。 服务器

  • 支持PDF,包括新旧MS Office格式。 测试

  • 在不离开触摸应用程序环境的情 最好支持从URL或.NET流中读取文档。 fetch

  • 无需在客户端计算机上安装额外的插件。网站

探索this

    接下来就是大量的研究探索,最终咱们寻找到了三个备选产品。url

Accusofts Prizm Client Connect 

    这款产品符合咱们的大多数标准,支持各类格式,但有一些缺点。它须要安装一个单独的服务器来进行文档转换。从他们提供下载的示例项目来判断,它须要编写大量代码才能使其打勾。除此以外,它只提供从文件路径加载文档的可能性。    

Snowbounds Virtualviewer 

    这款产品的必须做为服务器上的单独网站运行,能够经过添加提供程序来扩展文档的加载方式,在示例项目中支持文件和URL。可是用户界面有点拥挤,视觉体验不太好,并且还有许多不经常使用的功能。

虽然这两种产品可能已经完成了这项工做,但我测试的第三种产品可以弥补以上两种产品的缺点。

GroupDocs Viewer for .NET

    与其余产品相比,这是很轻便的一个产品,只需添加一个DLL便可,它有一个很是简洁的API。 最初不支持咱们想要的打印的要求,但在与Groupdocs.交谈并解释须要的功能后,他们很快就推出了解决它的新版本。

添加代码

在ASP.NET MVC应用程序中使用GroupDocs Viewer,必须完成四个步骤。

第一步:引用dll到项目中去

第二步:将如下项目加入Global.asax.

Viewer.InitRoutes();    
Viewer.SetRootStoragePath(Server.MapPath("SomePath")); // Documents will also be cached here    
Viewer.SetLicensePath(Server.MapPath("SomePathToYourLisenceFile"));

第三步:在web.config文件中添加一些处理程序。

<add name="ViewDocumentHandler" verb="GET,POST" path="document-viewer/ViewDocumentHandler" type="Groupdocs.Web.UI.Handlers.ViewDocumentHandler, Groupdocs.Viewer, Culture=neutral" />
<add name="GetDocumentPageImageHandler" verb="GET,POST" path="document-viewer/GetDocumentPageImageHandler" type="Groupdocs.Web.UI.Handlers.GetDocumentPageImageHandler, Groupdocs.Viewer, Culture=neutral" />
<add name="LoadFileBrowserTreeDataHandler" verb="GET,POST" path="document-viewer/LoadFileBrowserTreeDataHandler" type="Groupdocs.Web.UI.Handlers.LoadFileBrowserTreeDataHandler, Groupdocs.Viewer, Culture=neutral" />
<add name="GetImageUrlsHandler" verb="GET,POST" path="document-viewer/GetImageUrlsHandler" type="Groupdocs.Web.UI.Handlers.GetImageUrlsHandler, Groupdocs.Viewer, Culture=neutral" />
<add name="GetCssHandler" verb="GET" path="document-viewer/CSS/GetCssHandler" type="Groupdocs.Web.UI.Handlers.CssHandler, Groupdocs.Viewer, Culture=neutral" />
<add name="images" verb="GET" path="document-viewer/images/*" type="Groupdocs.Web.UI.Handlers.EmbeddedImageHandler, Groupdocs.Viewer, Culture=neutral" />
<add name="GetScriptHandler" verb="GET,POST" path="document-viewer/GetScriptHandler" type="Groupdocs.Web.UI.Handlers.ScriptHandler, Groupdocs.Viewer, Culture=neutral" />
<add name="GetFileHandler" verb="GET" path="document-viewer/GetFileHandler" type="Groupdocs.Web.UI.Handlers.GetFileHandler, Groupdocs.Viewer, Culture=neutral" />
<add name="GetPdf2JavaScriptHandler" verb="GET,POST" path="document-viewer/GetPdf2JavaScriptHandler" type="Groupdocs.Web.UI.Handlers.GetPdf2JavaScriptHandler, Groupdocs.Viewer, Culture=neutral" />
<add name="GetPdfWithPrintDialogHandler" verb="POST" path="document-viewer/GetPdfWithPrintDialogHandler" type="Groupdocs.Web.UI.Handlers.GetPdfWithPrintDialogHandler, Groupdocs.Viewer, Culture=neutral" />
<add name="GetPrintableHtmlHandler" verb="GET,POST" path="document-viewer/GetPrintableHtmlHandler" type="Groupdocs.Web.UI.Handlers.GetPrintableHtmlHandler, Groupdocs.Viewer, Culture=neutral" />

第四步:在视图中加入如下内容

//loads the javascripts that groupsdocs viewer needs@Html.CreateViewerScriptLoadBlock().LoadJquery().LoadJqueryUi() 
@(Html.ViewerClientCode()
.TargetElementSelector("#documentContainer")
.Stream(SomeDotNetStream) // fetch document from a stream
//.Url("SomeUrl") fetch from a url
//.FilePath("SomeFile") fetch from filepath
.DocViewerId("SomeViewerId")
//different functionality can be turned on and off, this is just an example on how we have set them
.EnableRightClickMenu(true)
.ShowThumbnails(false)
.OpenThumbnails(false)
.ShowFolderBrowser(false)
.ShowDownload(false)
.ShowViewerStyleControl(false)
.ShowSearch(false)
.UsePdfPrinting(false)
.BackgroundColor("black")
.Width(960)
.Height(900)
.ZoomToFitWidth(true)
.Locale("nb-no")
)
相关文章
相关标签/搜索