Hyphenation
Hyphenation is a way to arrange text in a document more compactly. However, it is important to remember that hyphenation rules may vary depending on the language.
Hyphenation is not used as often today as it used to be. However, enabling hyphenation can significantly affect the layout and therefore the appearance of output documents in fixed page formats, such as PDF or XPS.
To ensure correct word hyphenation, language-specific hyphenation dictionaries are used.
Hyphenation Dictionaries
As mentioned, different languages have different hyphenation rules and norms. In this case, the best solution for proper hyphenation is to use special dictionaries.
Hyphenation dictionaries are language-specific rule sets that define valid hyphenation points in words. Wordize uses OpenOffice dictionaries and advanced algorithms to work with these dictionaries – this provides hyphenation results that are as close as possible to those of Microsoft Word.
OpenOffice uses the Hunspell engine for spell checking, hyphenation, and thesaurus functions. When you enable hyphenation, OpenOffice dictionaries consult the corresponding dictionary to decide where to insert hyphens in long words at line breaks. For example, the word “information” might be hyphenated as “in-for-ma-tion”, depending on the dictionary rules.
Loading Hyphenation Dictionaries
To use the hyphenation feature, first register a hyphenation dictionary, using the Hyphenation property.
The following code example shows how to load hyphenation dictionaries for the specified languages from a file:
Wordize.Settings.Hyphenation.RegisterDictionary("en-US", "hyph_en_US.dic");
Wordize.Settings.Hyphenation.RegisterDictionary("de-CH", "hyph_de_CH.dic");The following code example shows how to load hyphenation dictionaries for the specified language from a stream:
using var stream = File.OpenRead("hyph_de_CH.dic");
Wordize.Settings.Hyphenation.RegisterDictionary("de-CH", stream);In addition to pre-registering hyphenation dictionaries, you can register the required hyphenation dictionaries “by request”. Use the IHyphenationCallback interface to get requested languages:
Wordize.Settings.Hyphenation.Callback = new HyphenationRequestsCollector();
Converter.Create()
.From("DocumentIn.docx")
.To("DocumentOut.pdf")
.Execute();private class HyphenationRequestsCollector : IHyphenationCallback
{
public void RequestDictionary(string language)
{
Console.WriteLine(language);
}
}Hyphenation Dictionaries Examples
To see how words can be broken into syllables differently by the different OpenOffice hyphenation dictionaries for different languages, let’s take the word “International” as an example.
The following table shows the hyphenation options for a few languages:
| Language | Word | OpenOffice Hyphenation |
|---|---|---|
| English | International | In-ter-na-tion-al |
| Spanish | Internacional | In-ter-na-cio-nal |
| French | Internationale | In-ter-na-tio-nale |
| German | International | In-ter-na-tio-nal |
| Italian | Internazionale | In-ter-na-zio-na-le |
FAQ
Q: How do I enable hyphenation for a document?
A: Register the required hyphenation dictionaries for the languages you need before converting the document. Once the dictionaries are registered, Wordize automatically applies hyphenation during the conversion process.Q: Can I load a hyphenation dictionary from a stream instead of a file path?
A: Yes. Open the dictionary file as a stream and pass it toRegisterDictionary. Example:using var stream = File.OpenRead("hyph_fr_FR.dic"); Wordize.Settings.Hyphenation.RegisterDictionary("fr-FR", stream);Q: What should I do if Wordize requests a dictionary for a language I haven’t registered?
A: Implement theIHyphenationCallbackinterface. TheRequestDictionarymethod will be called with the missing language code, allowing you to load or download the appropriate dictionary at runtime.Q: Is it possible to use my own custom hyphenation dictionary?
A: Absolutely. Any dictionary that follows the Hunspell.dicformat can be registered withRegisterDictionary. This lets you tailor hyphenation rules to specialized vocabularies or industry terminology.Q: Does hyphenation affect only PDF output?
A: No. Hyphenation influences the layout of any fixed‑page output format, such as PDF, XPS, and also impacts the appearance of Word documents when they are saved after hyphenation is applied.