Aspose.Pdf offers developers to control the layout of text paragraphs using FirstLineIndent property of Text class. FirstLineIndent property is used to specify the indentation of the first line of the text paragraph. FirstLineIndent property also provides an exciting feature of creating left hanging text paragraphs and this is achieved simply by assigning a negative value to it.
To have a clear distinction between first line indentation and left hanging text, please refer the figure below:
In the example below, we are going to create a left hanging text paragraph by assigning a negative value to the FirstLineIndent property of Text object.
Code Snippet
[C#]
//Instantiate Pdf pbject by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create a new section in the Pdf object
Section sec1 = pdf1.Sections.Add();
//Set the left margin of the section
sec1.PageInfo.Margin.Left = 110;
//Set the right margin of the section
sec1.PageInfo.Margin.Right = 120;
//Create a new text paragraph and pass the text to its constructor as argument
Text t2 = new Text("A bool value that indicates" +
"whether the TrueType font is bold. " +
"This attribute is valid for TrueType fonts only.");
//Set the font size of the text in a text segment
t2.Segments[0].TextInfo.FontSize = 16;
//Set the left margin of the text paragraph
t2.Margin.Left = 60;
//Set the first line indentation of the text paragraph to a negative value for
//producing the effect of left hanging text paragraph
t2.FirstLineIndent = -6;
//Add this left hanging text paragraph to the section
sec1.Paragraphs.Add(t2);
[VB.NET]
'Instantiate Pdf pbject by calling its empty constructor
Dim pdf1 As Pdf = New Pdf()
'Create a new section in the Pdf object
Dim sec1 As Section = pdf1.Sections.Add()
'Set the left margin of the section
sec1.PageInfo.Margin.Left = 110
'Set the right margin of the section
sec1.PageInfo.Margin.Right = 120
'Create a new text paragraph and pass the text to its constructor as argument
Dim t2 As Aspose.Pdf.Text =
New Aspose.Pdf.Text("A bool value that indicates" & _
" whether the TrueType font is bold. " & _
"This attribute is valid for TrueType fonts only.")
'Set the font size of the text in a text segment
t2.Segments(0).TextInfo.FontSize = 16
'Set the left margin of the text paragraph
t2.Margin.Left = 60
'Set the first line indentation of the text paragraph to a negative value for
'producing the effect of left hanging text paragraph
t2.FirstLineIndent = -6
'Add this left hanging text paragraph to the section
sec1.Paragraphs.Add(t2)
[JAVA]
//Instantiate Pdf pbject by calling its empty constructor
Pdf pdf = new Pdf();
//Create a new section in the Pdf object
Section sec1 = pdf.getSections().add();
//Set the left margin of the section
sec1.getPageSetup().getMargin().setLeft(110);
//Set the right margin of the section
sec1.getPageSetup().getMargin().setRight(120);
//Create a new text paragraph and pass the text to its constructor as argument
Text t2 = new Text(sec1, "A bool value that indicates" +
"whether the TrueType font is bold. " +
"This attribute is valid for TrueType fonts only.");
//Set the font size of the text in a text segment
t2.getSegments().getAt(0).getTextInfo().setFontSize(16);
//Set the left margin of the text paragraph
t2.getMargin().setLeft(60);
//Set the first line indentation of the text paragraph to a negative value for
//producing the effect of left hanging text paragraph
t2.setFirstLineIndent(-6);
//Add this left hanging text paragraph to the section
sec1.getParagraphs().add(t2);
[XML]
<Pdf xmlns="Aspose.Pdf">
<Section PageMarginLeft="30" PageMarginRight="200">
<Text MarginTop="10" MarginLeft="60" FirstLineIndent="-6">
<Segment FontSize="16">
A bool value that indicates whether
the TrueType font is bold.This attribute
is valid for TrueType fonts only.
</Segment>
</Text>
</Section>
</Pdf>