I get install GroupDocs Viewer in my project.
and in global
Groupdocs.Web.UI.Viewer.InitRoutes();
Groupdocs.Web.UI.Viewer.SetRootStoragePath(Server.MapPath("~/DietTemplate/"));
and in controller
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();
and in view
@section Styles{
@Html.CreateViewerScriptLoadBlock().LoadJquery().LoadJqueryUi()
}
@(Html.ViewerClientCode()
.TargetElementSelector("#test")
.Stream(ViewBag.Stream,
ViewBag.Filename,
ViewBag.Extension,
ViewBag.FileDisplayName)
.ZoomToFitWidth()
)
Edit
add script in view
<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>
but don't show anything. :(
From the code you posted, I can see that you use the ViewData
dictionary on the Controller-side and the ViewBag
one on the View-side. Whereas you should use either the ViewData
OR the ViewBug
. They can’t be used simultaneously.
In case you want to use the ViewData
, then on the View instead of:
.Stream(ViewBag.Stream, ViewBag.Filename, ViewBag.Extension, ViewBag.FileDisplayName)
you should have these:
.Stream((Stream)ViewData["stream"], (String)ViewData["filename"], (String)ViewData["extension"], (String)ViewData["fileDisplayName"])
P.S. I work as a Developer Evangelist at GroupDocs.