Aspose.Pdf

Set Vertical Alignment of Paragraph to Baseline or Topline

Aspose.Pdf also allows to set the vertical alignment of the Text Segments in the Text paragraph. This feature is required sometimes when we need to write some Chemical Formula, Company Trade Marks, Symbols, Mathematical Figures with Powers etc.

 

There are two kinds of vertical alignments of Text Segments supported by Aspose.Pdf as follows:

 

 

To have a clear distinction between Baseline and Topline alignments, follow the figure below:

 

 

TextInfo class is vital to text format settings having all properties and methods required to control text formatting. Vertical alignment of Text Segments is also controlled by setting the IsBaseline property (of TextInfo class) to true or false.

 

To align the Text Segments vertical, follow these 2 points:

 

 

The default value of IsBaseline property is true. It means that by default, all Text Segments are baselined. So, to Topline the Text Segment , we have given an example below for your reference.

 

Code Snippet

 

[C#]

 

//Instantiate Pdf object by calling its empty constructor

Pdf pdf1 = new Pdf();

 

//Create a section in the Pdf object

Section sec1 = pdf1.Sections.Add();

 

//Create a new text paragraph with an initial text segment "Aspose"

Text text1 = new Text(sec1,"Aspose");

 

//Add the text paragraph to the section

sec1.Paragraphs.Add(text1);

 

//Create a new text segment into the text paragraph

Segment seg2 = text1.Segments.Add("TM");

 

//Set the vertical alignment of text segment "seg2" to Topline by setting

//IsBaseline property  ot seg2.TextInfo to true

seg2.TextInfo.IsBaseline=false;

 

//Save the Pdf

pdf1.Save(...);

 

[VB.NET]

 

'Instantiate Pdf object by calling its empty constructor

Dim pdf1 As Pdf =  New Pdf()

 

'Create a section in the Pdf object

Dim sec1 As Section =  pdf1.Sections.Add()

 

'Create a new text paragraph with an initial text segment "Aspose"

Dim text1 As Text =  New Text(sec1,"Aspose")

 

'Add the text paragraph to the section

sec1.Paragraphs.Add(text1)

 

'Create a new text segment into the text paragraph

Dim seg2 As Segment =  text1.Segments.Add("TM")

 

'Set the vertical alignment of text segment "seg2" to Topline by setting

'IsBaseline property  ot seg2.TextInfo to true

seg2.TextInfo.IsBaseline=false

 

'Save the Pdf

pdf1.Save(...)

 

[JAVA]

 

//Instantiate Pdf instance by calling its empty constructor

Pdf pdf1 = new Pdf();

 

//Create a new section in the Pdf object

Section sec1 = pdf1.getSections().add();

 

//Create a new text paragraph with an initial text segment "Aspose"

Text text1 = new Text(sec1,"Aspose");

 

//Add the text paragraph to the section

sec1.getParagraphs().add(text1);

 

//Create a new text segment into the text paragraph

Segment seg2 = text1.getSegments().add("TM");

 

//Set the vertical alignment of text segment "seg2" to Topline by setting

//BaseLineOffset a positive value

seg2.getTextInfo().setBaseLineOffset(3);

 

[XML]

 

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

  <Pdf xmlns="Aspose.Pdf">

   <Section>

           <Text>

                   <Segment>Aspose</Segment>

                   <Segment IsBaseline="false">TM</Segment>

           </Text>

   </Section>

  </Pdf>