We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose words for Java example for automatic hyphenation

Hi team,

Does Aspose words for Java supports word document feature automatic hyphenation? I tried the below example and don’t see hyphen in the generated document. Could you please provide a sample code if it is supported?

http://www.officetooltips.com/word/tips/using_automatic_hyphenation.html

Thanks,
Kumar

Document doc = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);
System.out.println(docBuilder.getParagraphFormat().getSuppressAutoHyphens());

docBuilder.getParagraphFormat().setSuppressAutoHyphens(true);
docBuilder.getCurrentParagraph().getParagraphFormat().setSuppressAutoHyphens(true);

System.out.println(docBuilder.getParagraphFormat().getSuppressAutoHyphens());

docBuilder.write(“Dfdsafdsa asdfdsaf asfddsa asfdlkjalkjdfas asdfsadfdsa asfddsafdsa asdfsadfdsa asfdsafdsa asfdsafds asfdsafs asfdsa adsfsadf sadf dsafdsf adsfj adsfsadfdsa asdfsadfdsa dsafdsafdsa asdfsafsaddddddddddasfdadsfdsaf adsfdsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”);

Hi Kumar,


Thanks for your inquiry. I am afraid, currently, there is no way to set “Auto Hyphenation” option using Aspose.Words. Your request has been linked to the appropriate issue (WORDSNET-2338) and you will be notified as soon as it is supported. Sorry for the inconvenience.

However, you can specify whether the new paragraph should be exempted from any hyphenation which is applied in the document settings i.e. suppose you have a hyphenated document and you want to insert a new paragraph without obeying the existing hyphenation settings, you can achieve this by setting “ParagraphFormat.SuppressAutoHyphens” value to true.

Best regards,

The issues you have found earlier (filed as WORDSNET-2338) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(5)

Hi Kumar,


It is to update you that we have made a new HyphenationOptions class public. HyphenationOptions instance is available as a readonly property on the Document class and contains the following properties to configure document hyphenation options:

///
/// Gets or sets value determining whether automatic hyphenation is turned on for the document.
/// Default value for this property is false.
///
public bool AutoHyphenation {get;set;}
///
/// Gets or sets the maximum number of consecutive lines that can end with hyphens.
/// Default value for this property is 0.
///
///
///

If value of this property is set to 0, any number of consecutive lines can end with hyphens.

///

The property does not have effect when saving to fixed page formats e.g. PDF.

///
public int ConsecutiveHyphenLimit {get;set;}
///
/// Gets or sets the distance in 1/20 of a point from the right margin within which you do not want
/// to hyphenate words.
/// Default value for this property is 360 (0.25 inch).
///
public int HyphenationZone {get;set;}
///
/// Gets or sets value determining whether words written in all capital letters are hyphenated.
/// Default value for this property is true.
///
public bool HyphenateCaps {get;set;}

Here is sample usage:

Document doc = new Document();
doc.getHyphenationOptions().setAutoHyphenation(true);
doc.getHyphenationOptions().setConsecutiveHyphenLimit(2);
doc.getHyphenationOptions().setHyphenationZone(720); // 0.5 inch
doc.getHyphenationOptions().setHyphenateCaps(false);

Hope, this helps.

Best regards,