The viewer.view produces an InvalidOperationException
with the message This is not a structured storage file.
The document is fine (opens fine in Word) and my code works ok with PDF documents - no errors and the HTML and page counts etc are correct.
What is the error referring to and how can I fix this?
@cdewarenglish
Thanks for contacting the support. It seems like it’s a bug, could you please provide the following information for further investigation:
- API version that you’re using
- Sample file
Thanks
Version: 21.1.0.0
Sample file: resume_eight.zip (19.6 KB)
Thanks,
Chris
@cdewarenglish
I’ve failed to reproduce the issue with sample_app.zip (20.8 KB) the single page output.zip (42.4 KB) was rendered.
Please share more details:
- Code snippet that you’re using or sample app
- Your environment and target framework
Thanks
Hi - as requested as snippet to demonstrate the fault. Is this correct?
The environment is Windows 10 and .NET Framework 4.8
var inputbytes = File.ReadAllBytes("file.docx");
MemoryStream mem = new MemoryStream(inputbytes);
string convertedHtml = string.Empty;
mem.Position = 0;
MemoryStream outputStream = new MemoryStream();
using (Viewer viewer = new Viewer(mem))
{
HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources((pagenumber) => outputStream, (pagenumber, pagestream) =>
{
pagestream.Seek(0, SeekOrigin.Begin);
using (StreamReader sr = new StreamReader(pagestream))
{
convertedHtml = sr.ReadToEnd(); // get the stream data as an HTML string
}
});
viewOptions.RenderToSinglePage = true;
viewer.View(viewOptions);
ViewInfoOptions viewInfoOptions = ViewInfoOptions.ForHtmlView();
ViewInfo viewInfo = viewer.GetViewInfo(viewInfoOptions);
}
Thanks,
Chris
@cdewarenglish
That’s right, thanks for the code snippet. Unfortunately, I can’t reproduce the issue on my local Windows 10 machine.
It looks like Viewer can’t detect filetype or detects filetype incorrectly because the memory stream is passed to the Viewer’s constructor.
Could you please try running the with sample_app_1.zip (21.1 KB). in your environment and share exception details and log.txt
file that will be created in the application directory?
One more thing, try passing LoadOptions
as second parameter of Viewer
constructor:
var filename = "resume_eight.docx";
var extension = Path.GetExtension(filename);
var filetype = FileType.FromExtension(extension);
LoadOptions loadOptions = new LoadOptions(filetype);
using (Viewer viewer = new Viewer(mem, loadOptions)) { ... }
While Viewer does support filetype detection this operation could be expensive so it is preferable to pass filetype when you know it.
Thanks
Thanks Vladimir, that solves it when I pass the FileType
in via the LoadOptions
.
Thanks for your quick response.
Chris.