Skip to main content
A newer version of this page is available. .

Hyphenation

  • 3 minutes to read

The RichEditControl can enable or suppress word hyphenation at line breaks.

When you load a document, the following scenarios are possible:

  • If the document contains soft hyphens, RichEditControl preserves them.
  • If the document has automatic hyphenation enabled, the DXRichEdit uses the currently linked hyphenation dictionaries to hyphenate the text. Note that the document layout may change.

Add a Hyphenation Dictionary

Link a dictionary that specifies hyphenation rules. The RichEditControl.HyphenationDictionaries property provides access to the dictionary collection. You can use two dictionary types:

  1. OpenOfficeHyphenationDictionary

    The OpenOffice hyphenation dictionary is a .dic file containing hyphenation patterns with specific encoding.

    The file can contain the following information:

    • LEFTHYPHENMIN - The minimum number of characters that must appear before the first hyphen.
    • RIGHTHYPHENMIN - The minimum number of characters that must appear after the last hyphen.

    Use the LeftHyphenMin and RightHyphenMin properties to change these parameters.

    You can download dictionaries from the OpenOffice Extensions Page. Note that the OpenOffice license cannot be used for commercial projects.

  2. CustomHyphenationDictionary

    A file with hyphenation patterns. It can contain a list of words divided into syllables (e.g., hy-phe-na-tion).

    The code sample below shows how to add hyphenation dictionaries:

    View Example

    //Load embedded dictionaries
    var openOfficePatternStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ConsoleApp1.hyphen.dic");
    var customDictionaryStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ConsoleApp1.hyphen_exc.dic");
    
    //Create dictionary objects
    CustomHyphenationDictionary exceptionsDictionary = new CustomHyphenationDictionary(customDictionaryStream, new System.Globalization.CultureInfo("EN-US"));
    OpenOfficeHyphenationDictionary hyphenationDictionary = new OpenOfficeHyphenationDictionary(openOfficePatternStream, new System.Globalization.CultureInfo("EN-US"));
    
    //Add them to the word processor's collection
    richEditControl.HyphenationDictionaries.Add(exceptionsDictionary);
    richEditControl.HyphenationDictionaries.Add(hyphenationDictionary);
    

Dictionary Culture

The RichEditControl uses dictionaries that match the document’s culture. You can specify the dictionary’s culture in the object constructor. If the culture is not specified, the dictionary’s culture is set to the machine’s current culture.

Hyphenate Text

Use the following properties to hyphenate document text:

Property Description
Document.Hyphenation Specifies whether to hyphenate text automatically. If dictionaries are not provided, the property has no effect.
Document.HyphenateCaps Gets or sets whether to hyphenate words in CAPS.
Paragraph.SuppressHyphenation Specifies whether to limit hyphenation to a specific paragraph.

The code sample below shows how to enable hyphenation and export a document to the PDF format.

//Load a document
richEditControl.LoadDocument("Grimm.docx");

//Specify hyphenation settings
richEditControl.Document.Hyphenation = true;
richEditControl.Document.HyphenateCaps = true;

//Export the result to the PDF format
richEditControl.ExportToPdf("Result.pdf");

//Open the result
Process.Start("Result.pdf");

Hyphenation in the User Interface

End user can press Ctrl+- to insert soft hyphens where necessary. Use the Hyphenation drop-down list on the Page Layout ribbon tab to enable or suppress automatic hyphenation, and specify additional hyphenation options. If dictionaries are not provided, the list is disabled.

IMAGE

The Hyphenation Dialog allows you to enable automatic hyphenation and specify whether to hyphenate words in CAPS.

dialog

Use the Paragraph Dialog to suppress hyphenation for a specific paragraph. On the Line and Page Breaks tab, check the Don’t Hyphenate item.

suppress hyphenation