Conversion issues - from RTF to Docx to RTF

Hi, we’re facing some issues while trying to convert from RTF document to Docx and then switching back to RTF.

There are no errors while executing the code below but when we compare the source and the destination RTF files they mismatch because the destination file has been enriched with additionals markers and tags.
This cause an issue while importing the RTF to our SAP r/3 cause SAP doesn’t allow the additionals markers.

Is there a setup to apply to RtfSaveOptions to avoid this behaviour?

Attached you find the source and the destination files.
Below the sample code:

using (var ms = new MemoryStream(EmbeddedResource.ReadByteArray(“ZP40F190000_DE.rtf”)))
{
// Load the document.
LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFormat = LoadFormat.Rtf;

Aspose.Words.Document doc = new Document(ms, loadOptions);
doc.ApplyTransformation(Models.DocumentFormat.DocX);

// Save the document to DocX.
SaveToDocX(doc, “test.docx”);

// Load the output document.
loadOptions.LoadFormat = LoadFormat.Auto;
doc = new Document(“C:\test.docx”, loadOptions);
doc.ApplyTransformation(Models.DocumentFormat.DocX);

// Save the document to RTF.
SaveToRtf(doc, “test.rtf”);
}


private void SaveToDocX(Aspose.Words.Document doc, string fileName)
{
var saveOptions = new OoxmlSaveOptions(SaveFormat.Docx);
doc.Save(Path.Combine(“C:\”, fileName), saveOptions);
}

private void SaveToRtf(Aspose.Words.Document doc, string fileName)
{
var saveOptions = new RtfSaveOptions();
doc.Save(Path.Combine(“C:\”, fileName), saveOptions);
}

///
/// Apply the required transformation to Aspose.Words.Document.
///
[System.Diagnostics.DebuggerStepThrough]
public static Aspose.Words.Document ApplyTransformation(this Aspose.Words.Document source, DocumentFormat format)
{
FontChanger changer = new FontChanger(“Verdana”, 10);
source.Accept(changer);
return source;
}

FontChanger is taken from your forums. It changes the default font to the one passed as argument.

Kind regards,
Talea
Hi Talea,

Thanks for your inquiry.

In your case, we suggest you please set the value of RtfSaveOptions.ExportCompactSize property to true. This will make the output RTF document smaller in size. Please also use latest version of Aspose.Words for .NET 16.12.0. Hope this helps you.

If you still face problem, please share which additional markers and tags you want to remove from the document. We will then provide you more information on this.

Hi Tahir,


I’ve downloaded the version you suggested, referenced to the project and added the ExportCompactSize property you suggested but stills the file has huge size.

These are the tags I want to remove, and every tag which starts with those strings (i.e: lsdpriority70, lsdpriority61, lsdpriority65, etc):
\lsdpriority, \lsdsemihidden, \lsdunhideused, \lsdqformat

Thank you
Hi Talea,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If you first convert RTF to Docx and then Docx to RTF using MS Word, you will get the same output.

Could you please share your expected output RTF document here for our reference? We will then provide you more information about your query.