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

本文章对比三款HTML5文档查看器,最终选出干净简便的文档查看器——GroupDocs.Viewer。

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

GroupDocs.Viewer试用版


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

 经过探讨,我们制定了以下标准:

  • 适用于Windows Server和.NET。 

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

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

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

探索

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

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"))

    如对以上内容存有疑惑,可以点击在线客服>>解答疑惑

    年中活动,优惠多多,点击就可领取 MyEclipse 、.NET ReactorFastReport .NetVMProtect等超多在线订购产品优惠券!

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

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年5月18日
下一篇 2019年5月18日

相关推荐

发表回复

登录后才能评论