b2xtranslator
b2xtranslator copied to clipboard
"Stream with name 'WordDocument' not found."
I keep getting this issue when I try to use this library
`
var file = new FileInfo(Input);
var reader = new StructuredStorageReader(file.FullName);
var doc = new b2xtranslator.DocFileFormat.WordDocument(reader);
var docx = WordprocessingDocument.Create(Output, b2xtranslator.OpenXmlLib.OpenXmlPackage.DocumentType.Document);
b2xtranslator.WordprocessingMLMapping.Converter.Convert(doc, docx);
` It throws in the instantiation of the WordDocument
Cheers for the feedback @NamelessHH!
As a first step please could you add a unit test to the testing project that throws the exception you're seeing? That will give us a starting point for the issue. Thanks.
I get this issue when running on Linux - same code works fine on Windows. I haven't had time to investigate much but from what I can see the issue is with StructuredStorageReader._directory - in Linux, the name property of all the entries is string.Empty.
@fergalmoran Have you found whatt casuses the issue?
@tomaszzmuda - sorry, no. I gave up and used libreoffice api instead.
Just ran into this while using the library. The problem is in https://github.com/EvolutionJobs/b2xtranslator/blob/90d05a6589706cf177a245fcb74e9cba4b6264ae/Common/StructuredStorage/Common/InternalBitConverter.cs#L64.
Document metadata streams begin with a unicode character like "\u0005DocumentSummary\0\0\0\0\0\0". In windows, if you call .IndexOf("\0")
on that string, it will treat the "\u0005" as a single unmatching character and return the index of the first \0
after DocumentSummary. In Linux, the null byte that is part of the "\u0005" character will get detected and it will delete everything after the initial byte.
Just replace the result = result.Remove(result.IndexOf("\0"));
line with result = result.TrimEnd('\0');
and it works fine.
The fix by michaelweber helped get past this error on .NET 6. Are there updates to nuget planned?