Word Processing - Character Spacing Options, Wrapped Tables and Custom XML Parts (v20.1)

Both the DevExpress Rich Text Editor and Word Processing Document API (v20.1) ship with new table, character formatting and additional content-related capabilities. In this post, we’ll summarize what you can expect in v20.1 and how you can leverage these features in your next app.

Wrap Text Around a Table

Our RTF/Word Processing components (WinForms, WPF, API) allow you to wrap text around a table and specify the table’s position.

We added new API members and User Interface elements to manage/modify table positioning options.

The code sample below demonstrates how you can wrap text around a table:

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
  Document document = wordProcessor.Document;
  Table table = document.Tables[0];
  table.BeginUpdate();
  //Wrap text around the table
  table.TextWrappingType = TableTextWrappingType.Around;

  //Specify vertical alignment:
  table.RelativeVerticalPosition = TableRelativeVerticalPosition.Margin;
  table.VerticalAlignment = TableVerticalAlignment.Center;

  //Specify horizontal alignment:
  table.RelativeHorizontalPosition = TableRelativeHorizontalPosition.Margin;
  table.HorizontalAlignment = TableHorizontalAlignment.Center;

  //Set distance between the text and the table:
  table.MarginBottom = Units.InchesToDocumentsF(0.2f);
  table.MarginLeft = Units.InchesToDocumentsF(0.2f);
  table.MarginTop = Units.InchesToDocumentsF(0.1f);
  table.MarginRight = Units.InchesToDocumentsF(0.2f);
  table.EndUpdate();
}

Character Properties Enhancements

This release include new character formatting options. You can now specify spacing, position, kerning threshold and a horizontal scale.

The code example below demonstrates how to specify these options in code:

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer()) 
{
    Document document = wordProcessor.Document;

    //Change formatting options for the first paragraph:
    DocumentRange range = document.Paragraphs[0].Range;
    CharacterProperties cp = document.BeginUpdateCharacters(range);
    cp.Scale = 150;
    cp.Spacing = -2;
    cp.Position = 2;
    document.EndUpdateCharacters(cp);
}

Our Rich Text Editor/Word Processing components (WinForms and WPF) ship with a new Font dialog tab used to change character spacing parameters.

Custom XML Parts

You can now embed arbitrary XML data (called custom XML parts) within documents (DOCX and DOC formats). You can create, modify or remove custom XML parts, obtain associated content and display it in a document.

The code sample below demonstrates how to retrieve employee names from a custom XML part and display them in the main document.

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    Document document = wordProcessor.Document;
    
    // Load a document.
    document.LoadDocument("Document.docx");
    
    // Access a custom XML file stored in the document.
    XmlDocument xmlDoc = document.CustomXmlParts[0].CustomXmlPartDocument;
    
    // Retrieve employee names from the XML file and display them in the document.
    XmlNodeList nameList = xmlDoc.GetElementsByTagName("Name");
    document.AppendText("Employee list:");
    foreach (XmlNode name in nameList)
    {
        document.AppendText("\r\n \u00B7 " + name.InnerText);
    }
}

Please refer to the following GitHub repository for more code samples: Custom XML Parts Examples

Your Feedback Matters

As always, we welcome your thoughts. Please comment below and let us know what you think of these new features. Once again, should you have technical questions, feel free to contact us via the DevExpress Support Center.

What’s New in v20.1

To explore the scope, breadth and capabilities of our new products/features, please visit: https://www.devexpress.com/Subscriptions/New-2020-1.xml.
No Comments

Please login or register to post comments.