Right-to-left aligned languages such as Arabic, Hebrew and Urdu are also supported in Aspose.Pdf . TextInfo.IsRightToLeft property can be used for any Text Segment to specify whether to align the text from right to left or not.
TextInfo.IsRightToLeft is a boolean property that can be set to true or false to achieve the desired output.
Note:Currently only normal fonts such as "Times New Roman" are supported. Specific fonts such as "Traditional Arabic" are not supported.
The following example shows how to use right-to-left aligned language.
Code Snippet
[C#]
Pdf pdf = new Pdf();
pdf.Sections.Add();
pdf.IsTruetypeFontMapCached = true;
pdf.TruetypeFontMapPath = @"d:\test";
//Create a text object and pass the string object carrying arabic text in it
Aspose.Pdf.Text text1 = new Aspose.Pdf.Text();
Aspose.Pdf.Segment seg0 = text1.Segments.Add();
seg0.Content = "أسبوز هو بائع عنصر ال";
Aspose.Pdf.Segment seg1 = text1.Segments.Add();
seg1.Content = ".NET";
Aspose.Pdf.Segment seg2 = text1.Segments.Add();
seg2.Content = "البارز";
//Enable text alignment from right to left
seg0.TextInfo.IsRightToLeft = true;
seg1.TextInfo.IsRightToLeft = false; //default
seg2.TextInfo.IsRightToLeft = true;
//Enable unicode character set for the text segment
seg0.TextInfo.IsUnicode = true;
seg1.TextInfo.IsUnicode = true;
seg2.TextInfo.IsUnicode = true;
//Set Font Name
seg0.TextInfo.FontName = "Times New Roman";
seg1.TextInfo.FontName = "Times New Roman";
seg2.TextInfo.FontName = "Times New Roman";
//Set font size
seg0.TextInfo.FontSize = 14;
seg1.TextInfo.FontSize = 14;
seg2.TextInfo.FontSize = 14;
//Align text to right hand side using AlignmentType enumeration
//Make the text right aligned(The meaning of Alignment.Left and AlignmentType.Right are //exchanged when processing RTL language).
text1.TextInfo.Alignment = AlignmentType.Left;
pdf.Sections[0].Paragraphs.Add(text1);
pdf.IsRtlInSegmentMode = true; //default
pdf.Save(@"d:/Test/test.pdf");
[VB.NET]
Dim pdf As Pdf = New Pdf
pdf.Sections.Add()
pdf.IsTruetypeFontMapCached = True
pdf.TruetypeFontMapPath = "d:\test"
'Create a text object and pass the string object carrying arabic text in it
Dim text1 As Aspose.Pdf.Text = New Aspose.Pdf.Text
Dim seg0 As Aspose.Pdf.Segment = text1.Segments.Add()
seg0.Content = "أسبوز هو بائع عنصر ال"
Dim seg1 As Aspose.Pdf.Segment = text1.Segments.Add()
seg1.Content = ".NET"
Dim seg2 As Aspose.Pdf.Segment = text1.Segments.Add()
seg2.Content = "البارز"
'Enable text alignment from right to left
seg0.TextInfo.IsRightToLeft = True
seg1.TextInfo.IsRightToLeft = False 'default
seg2.TextInfo.IsRightToLeft = True
'Enable unicode character set for the text segment
seg0.TextInfo.IsUnicode = True
seg1.TextInfo.IsUnicode = True
seg2.TextInfo.IsUnicode = True
'Set Font Name
seg0.TextInfo.FontName = "Times New Roman"
seg1.TextInfo.FontName = "Times New Roman"
seg2.TextInfo.FontName = "Times New Roman"
'Set font size
seg0.TextInfo.FontSize = 14
seg1.TextInfo.FontSize = 14
seg2.TextInfo.FontSize = 14
'Align text to right hand side using AlignmentType enumeration
'Make the text right aligned(The meaning of Alignment.Left and AlignmentType.Right are 'exchanged when processing RTL language).
text1.TextInfo.Alignment = AlignmentType.Left
pdf.Sections(0).Paragraphs.Add(text1)
pdf.IsRtlInSegmentMode = True 'default
pdf.Save("d:/Test/test.pdf")
[XML]
<?xml version="1.0" encoding="UTF-8"?>
<Pdf xml:space="preserve" TabStopPosition="36" IsCoreFontUsed="false" IsRTLSegmentMode="true" xmlns="Aspose.Pdf">
<Section PageWidth="612" PageHeight="792" PageMarginTop="72" PageMarginBottom="72" PageMarginLeft="90" PageMarginRight="90" IsNewPage="true">
<Text>
<Segment FontName="Times New Roman" FontSize="14" IsUnicode="true" IsRightToLeft="true">أسبوز هو بائع عنصر ال</Segment>
<Segment FontName="Times New Roman" FontSize="14" IsUnicode="true" IsRightToLeft="false">.NET</Segment>
<Segment FontName="Times New Roman" FontSize="14" IsUnicode="true" IsRightToLeft="true">البارز</Segment>
</Text>
</Section>
</Pdf>