1

我在我的项目中安装了 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>

但不要显示任何东西。:(

4

1 回答 1

1

从您发布的代码中,我可以看到您ViewData在控制器端使用字典,ViewBag在视图端使用字典。而您应该使用ViewData ORViewBug. 它们不能同时使用。

如果您想使用ViewData, 则在 View 上而不是:

.Stream(ViewBag.Stream, ViewBag.Filename, ViewBag.Extension, ViewBag.FileDisplayName)

你应该有这些:

.Stream((Stream)ViewData["stream"], (String)ViewData["filename"], (String)ViewData["extension"], (String)ViewData["fileDisplayName"])

PS 我在 GroupDocs 担任开发人员布道师。

于 2015-02-20T15:52:40.367 回答