Aspose.Pdf

Using hyphenation while creating PDF.

 

Hyphenation

If a word is too long to fit on the end of a line, the word is moved to the beginning of the next line instead of hyphenating it. However, in Microsoft Word you can use the hyphenation feature to insert hyphens to eliminate gaps in justified text or to maintain even line lengths in narrow columns. A hyphen is used to prevent a hyphenated word, number, or phrase from breaking if it falls at the end of a line. For example, you can prevent 555-0123 from breaking; instead, the entire item moves to the beginning of the next line.

 

Based on the customized hyphenation dictionary, Aspose.Pdf allows creating hyphenations in a Pdf document and supports the following features does.

 

Feature

Data Type

Switching hyphenation ON/OFF

Boolean

Option to hyphenate words in Pdf/Section/Text & Heading/Segment.

Boolean

Maximum number of consecutive hyphenation happened.

Integer.

Width of hyphenation zone.

Floating point number, “cm” and “inch”.

 

Below is an example of the hyphenation dictionary file (*.xml):

 

<?xml version="1.0" encoding="UTF-8" ?>

<HyphenationInfo xmlns="AsposePdf.Hyphen">

  <HyphenChar Value="-" />

  <Word Name="networks">net-works</Word>

  <Word Name="simulation">simu-la-tion</Word>

  <Word Name="unfortunately">un-for-tu-nately</Word>

  <Word Name="authentication">au-then-ti-ca-tion</Word>  

</HyphenationInfo>

 

Instructions for creating Hyphenation dictionary:

The comment must not be inserted into the content of a <Word> element.

If the word is not included in the dictionary file, Aspose.Pdf will hyphenate the word automatically according to its width.

 

Please follow the Instruction for creating a Pdf file with hyphenations:

Create an instance of pdf document class.

Set the value of Hyphenation property to true ie. pdf. IsAutoHyphenated.

Set the value for pdf. HyphenationDictionaryPath to specify customized hyphenation dictionary path.

 

Code Snippet

 

[C#]

//Create pdf document

Pdf pdf1 = new Pdf();

 

//Instantiate License class and call its SetLicense method to use the license

Aspose.Pdf.License license = new Aspose.Pdf.License();

license.SetLicense("Aspose.Pdf.lic");

 

//Bind XML into the document

pdf1.BindXML("../../../Hyphen-test.xml",null); 

 

//Enable hyphenation function. Default value is false.

pdf1.IsAutoHyphenated = true;

 

//Set the hyphenation dictionary path.

pdf1.HyphenationDictionaryPath = @"c:\temp\Hyphen.xml"

 

//Set the hyphenation area width. Default value is 12 points.

pdf1.HyphenationZoneWidth = 0;

 

//Set the maximum number of consecutive hyphenations. Default value is zero that means no //limits.

pdf1.ConsecutiveHyphensLimits = 0;

//Save the document

pdf1.Save("Hyphen-test.pdf");

 

 

[VB.NET]

'Create pdf document

Dim pdf1 As Pdf = New Pdf()

 

'Instantiate License class and call its SetLicense method to use the license

Dim license As license = New license

License.SetLicense("Aspose.Pdf.lic")

 

'Bind XML into the document

pdf1.BindXML("../../../Hyphen-test.XML",null); 

 

'Enable hyphenation function. Default value is false.

pdf1.IsAutoHyphenated = true;

 

'Set the hyphenation dictionary path.

pdf1.HyphenationDictionaryPath = @"c:\temp\Hyphen.xml"

 

'Set the hyphenation area width. Default value is 12 points.

pdf1.HyphenationZoneWidth = 0;

 

'Set the maximum number of consecutive hyphenations. Default value is zero that means no 'limits.

pdf1.ConsecutiveHyphensLimits = 0;

'Save the document

pdf1.Save("Hyphen-test.pdf");

 

[Hyphen-test.xml]

<?xml version="1.0" encoding="utf-8" ?>

  <Pdf xmlns="Aspose.Pdf" IsAutoHyphenated="true" >

   <Section>

<Heading Level="1">

<Segment IsAutoHyphenated="true">hyphen test1</Segment>

</Heading>

<Text>

<Segment IsAutoHyphenated="false">hyphen test2</Segment>

    </Text>

   </Section>

  </Pdf>