The following code snippet shows how to render to HTML with embedded resources and to provide the output result as a stream. To do this, it implements the IPageStreamFactory interface only.
usingSystem.IO;usingSystem.Collections.Generic;usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;usingGroupDocs.Viewer.Interfaces;// ...// Create the list to store output pagesList<MemoryStream>pages=newList<MemoryStream>();using(Viewerviewer=newViewer("sample.docx")){MemoryPageStreamFactorypageStreamFactory=newMemoryPageStreamFactory(pages);ViewOptionsviewOptions=HtmlViewOptions.ForEmbeddedResources(pageStreamFactory);viewer.View(viewOptions);}internalclassMemoryPageStreamFactory:IPageStreamFactory{privatereadonlyList<MemoryStream>_pages;publicMemoryPageStreamFactory(List<MemoryStream>pages){_pages=pages;}publicStreamCreatePageStream(intpageNumber){MemoryStreampageStream=newMemoryStream();_pages.Add(pageStream);returnpageStream;}publicvoidReleasePageStream(intpageNumber,StreampageStream){//Do not release page stream as we'll need to keep the stream open}}
ImportsSystem.IOImportsGroupDocs.ViewerImportsGroupDocs.Viewer.OptionsImportsGroupDocs.Viewer.Interfaces' ...
ModuleProgramSubMain(argsAsString())' Create the list to store output pages
DimpagesAsNewList(OfMemoryStream)()UsingviewerAsNewViewer("sample.docx")DimpageStreamFactoryAsNewMemoryPageStreamFactory(pages)DimviewOptionsAsViewOptions=HtmlViewOptions.ForEmbeddedResources(pageStreamFactory)viewer.View(viewOptions)EndUsingEndSubClassMemoryPageStreamFactoryImplementsIPageStreamFactoryPrivateReadOnly_pagesAsList(OfMemoryStream)PublicSubNew(pagesAsList(OfMemoryStream))_pages=pagesEndSubPublicFunctionCreatePageStream(pageNumberAsInteger)AsStreamImplementsIPageStreamFactory.CreatePageStreamDimpageStreamAsNewMemoryStream()_pages.Add(pageStream)ReturnpageStreamEndFunctionPublicSubReleasePageStream(pageNumberAsInteger,pageStreamAsStream) _
ImplementsIPageStreamFactory.ReleasePageStream'Do not release page stream as we'll need to keep the stream open
EndSubEndClassEndModule
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.