In tables, when a table header is too long and breaks onto a new line, I need a hyphen to appear before the word breaks

Table Header issue.docx (45.7 KB)

@Suriya08

To ensure that a hyphen appears before a word when a table header is too long and breaks onto a new line, you can utilize the hyphenation feature in Aspose.Words. This feature allows you to control where words can be hyphenated, which helps achieve the desired formatting.

Here’s a step-by-step solution to implement hyphenation in your document:

  1. Load Your Document: Start by loading your document using Aspose.Words.
  2. Register a Hyphenation Dictionary: Use a hyphenation dictionary for the desired language to enable hyphenation.
  3. Set Hyphenation Options: Configure the hyphenation options for your document to enable hyphenation and adjust the hyphenation zone as needed.
  4. Save the Document: Finally, save the document in your desired format.

Here’s a basic example of how to implement hyphenation in your document:

using Aspose.Words;
using Aspose.Words.Hyphenation;

// Load your document
Document doc = new Document("YourDocument.docx");

// Register a hyphenation dictionary for the desired language
using (Stream dictionaryStream = new FileStream("hyph_en_US.dic", FileMode.Open))
{
    Hyphenation.RegisterDictionary("en-US", dictionaryStream);
}

// Set the hyphenation options for the document
doc.HyphenationOptions = new HyphenationOptions
{
    HyphenationEnabled = true,
    HyphenationZone = 100 // Adjust the zone as needed
};

// Save the document
doc.Save("OutputDocument.pdf");

Make sure to replace "YourDocument.docx" and "hyph_en_US.dic" with the actual paths to your document and hyphenation dictionary file. This code will enable hyphenation in your document, allowing for better control over how long words are split across lines, including the addition of hyphens.

If you have any further questions or need additional assistance, please feel free to ask!