Hello!)
I meet the following problem using GroupDocs.Conversion for RTF/DOC to DOCX conversion: the converted file content looks like encoded byte array instead of the readable text as in the source file:
Here is my code example of how I use the library and in attached zip you can find source(.rtf) and converted (.docx) files. Probably I miss some options or this is only because of evaluation version of GroupDocs.Conversion?
using (var fTemp = new FileStream(@"D:\test1.rtf", FileMode.Open, FileAccess.Read))
{
using (var converter = new Converter(
() => fTemp,
(LoadContext context) => null))
{
var options = converter.GetPossibleConversions()["docx"]
.ConvertOptions;
converter.Convert(options,
(ConvertedContext convertedContext)
=>
{
using var fs = File.Create(@"D:\\test2.docx");
convertedContext.ConvertedStream.CopyTo(fs);
});
}
}
test.zip (68.7 KB)
@atsar0621
To resolve the issue of the converted DOCX file displaying content as an encoded byte array instead of readable text, you should explicitly specify the input file format when initializing the converter. This can be done using WordProcessingLoadOptions
to set the format to RTF. Here’s how you can modify your code:
using System;
using System.IO;
using GroupDocs.Conversion;
using GroupDocs.Conversion.Options.Convert;
class Program
{
static void Main()
{
using (var fTemp = new FileStream(@"D:\test1.rtf", FileMode.Open, FileAccess.Read))
{
var loadOptions = new WordProcessingLoadOptions
{
Format = WordProcessingFileType.Rtf // Specify the input format
};
using (var converter = new Converter(() => fTemp, (LoadContext context) => loadOptions))
{
var options = new WordProcessingConvertOptions(); // You can customize conversion options here
using var fs = File.Create(@"D:\test2.docx");
converter.Convert(options, (ConvertedContext convertedContext) =>
{
convertedContext.ConvertedStream.CopyTo(fs);
});
}
}
}
}
In this code, the loadOptions
variable is created to specify that the input file format is RTF. This should help ensure that the conversion process correctly interprets the content of the RTF file, resulting in a properly formatted DOCX file.
For more detailed examples and documentation, you can refer to the official GroupDocs conversion documentation here.
If you continue to experience issues, it may be worth checking if the evaluation version of GroupDocs.Conversion has any limitations that could affect the conversion process.
Sources:
[1]: Conversion gives an crazy error
[2]: ConvertRtfToDocx.cs
@atsar0621
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CONVERSIONNET-7648
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Hi @Professionalize.Discourse, thank you for your reply but unfortunatelly the issue is still reproduceable even after specifieng the input format in loadOptions((
@atsar0621
This issue is reproduced at our end, we are already investigating it. You’ll be notified in case of any progress update.