我在我的项目中安装了 GroupDocs Viewer。
并且在全球
Groupdocs.Web.UI.Viewer.InitRoutes();
Groupdocs.Web.UI.Viewer.SetRootStoragePath(Server.MapPath("~/DietTemplate/"));
并在控制器中
var ByteStream = new FileStream(Server.MapPath("~/DietTemplate/L0.docx"),
FileMode.Open, FileAccess.Read, FileShare.Read);
//ViewData
ViewData["stream"] = ByteStream;
ViewData["filename"] = "L0.docx";
ViewData["extension"] = "docx";
ViewData["fileDisplayName"] = "Defined document.pdf";
return View();
并且在视野中
@section Styles{
@Html.CreateViewerScriptLoadBlock().LoadJquery().LoadJqueryUi()
}
@(Html.ViewerClientCode()
.TargetElementSelector("#test")
.Stream(ViewBag.Stream,
ViewBag.Filename,
ViewBag.Extension,
ViewBag.FileDisplayName)
.ZoomToFitWidth()
)
编辑
在视图中添加脚本
<script type="text/javascript"> $(function () { var localizedStrings = null;var thumbsImageBase64Encoded = null;$('#test').groupdocsViewer({ localizedStrings: localizedStrings, thumbsImageBase64Encoded: thumbsImageBase64Encoded, filePath: 'temp\\S\\L0.docx',quality: 100,showThumbnails: true,openThumbnails: true,initialZoom: 100,zoomToFitWidth: true,onlyShrinkLargePages: false,zoomToFitHeight: false,width: 0,height: 0,backgroundColor: null,showFolderBrowser: true,showPrint: true,showDownload: true,showZoom: true,showPaging: true,showViewerStyleControl: true,showSearch: true,preloadPagesCount: null,preloadPagesOnBrowserSide: false,convertWordDocumentsCompletely: false,viewerStyle: 1,supportTextSelection: true,usePdfPrinting: false,toolbarButtonsBoxShadowStyle: null,toolbarButtonsBoxShadowHoverStyle: null,thumbnailsContainerBackgroundColor: null,thumbnailsContainerBorderRightColor: null,toolbarBorderBottomColor: null,toolbarInputFieldBorderColor: null,toolbarButtonBorderColor: null,toolbarButtonBorderHoverColor: null,thumbnailsContainerWidth: 0,jqueryFileDownloadCookieName: 'jqueryFileDownloadJSForGD',showDownloadErrorsInPopup: false,showImageWidth: false,showHeader: true,minimumImageWidth: 0,enableStandardErrorHandling: true,useHtmlBasedEngine: false,useHtmlThumbnails: false,useImageBasedPrinting: true,fileDisplayName: 'Defined document.pdf',downloadPdfFile: false,searchForSeparateWords: false,preventTouchEventsBubbling: false,useInnerThumbnails: false,watermarkText: null,watermarkColor: null,watermarkPosition: 'Diagonal',watermarkFontSize: 0,printWithWatermark: false,supportPageReordering: false,searchHighlightColor: null,currentSearchHighlightColor: null,treatPhrasesInDoubleQuotesAsExactPhrases: false,usePngImagesForHtmlBasedEngine: false,showOnePageInRow: false,loadAllPagesOnSearch: false,useEmScaling: false,ignoreDocumentAbsence: false,supportPageRotation: false,useRtl: false,useAccentInsensitiveSearch: false,useVirtualMode: false,supportListOfContentControls: false,supportListOfBookmarks: false,embedImagesIntoHtmlForWordFiles: false}); }); </script>
但不要显示任何东西。:(