How to get HTML when using MemoryPageStreamFactory

Hi @vladimir.litvinchik,

Please help us with below code.

 string returnContent = string.Empty;
 inputFile.Position = 0;
 FileType fileType = FileType.FromExtension(fileExtension);
 LoadOptions loadOptions = new LoadOptions(fileType);
 List<MemoryStream> pages = new List<MemoryStream>();
 using (Viewer viewer = new Viewer(inputFile, loadOptions))
{
     MemoryPageStreamFactory pageStreamFactory = new MemoryPageStreamFactory(pages);
     HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageStreamFactory);
     //to get all data in one file
     options.RenderToSinglePage = true;
     viewer.View(options);
}      
return returnContent;

I want to read the stream that we have in pageStreamFactory . Can you help us how we can do so.

Thanks,


This Topic is created by vladimir.litvinchik using Email to Topic tool.

@VikashVerma551

To get HTML you can convert a page using Encoding.UTF8.GetString method.

 string returnContent = string.Empty;
 inputFile.Position = 0;
 FileType fileType = FileType.FromExtension(fileExtension);
 LoadOptions loadOptions = new LoadOptions(fileType);
 List<MemoryStream> pages = new List<MemoryStream>();
 using (Viewer viewer = new Viewer(inputFile, loadOptions))
 {
     MemoryPageStreamFactory pageStreamFactory = new MemoryPageStreamFactory(pages);
     HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageStreamFactory);
     //to get all data in one file
     options.RenderToSinglePage = true;
     viewer.View(options);
 }
 
 byte[] firstPage = pages.First().ToArray();
 returnContent = Encoding.UTF8.GetString(firstPage);
1 Like

@vladimir.litvinchik Thanks for the support it worked now

@VikashVerma551

You’re welcome!