Introduction
Apitron PDF Kit for .NET
component fully supports right to left texts written in languages such as
Arabic, Hebrew and others, as well as bi-directional writings created by mixing
RTL and LTR languages. In this article we’ll show how to create a PDF document
containing all these variations.
The code
Code sample below creates a grid in on PDF page which
contains LTR, BIDI and RTL text blocks.
class Program
{
static void Main(string[] args)
{
//
create flow document
FlowDocument doc = new FlowDocument()
{
Margin = new Thickness(10)
};
//
register style for grid rows
doc.StyleManager.RegisterStyle("gridrow", new Style()
{
Font = new Font("Traditional Arabic", 20),
Align = Align.Center
});
//
register style for header row
doc.StyleManager.RegisterStyle("gridrow.header",new Style()
{
Background = RgbColors.Gray,
Color = RgbColors.White,
Font = new Font(StandardFonts.Helvetica,
20)
});
//
create grid
Grid grid = new Grid(150,Length.Auto, 150);
// add
header row
grid.Add(new GridRow(new TextBlock("LTR"),new TextBlock("BIDI"),
new TextBlock("RTL")){Class = "header"});
// add
content row
grid.Add(new GridRow(
new TextBlock("Apitron PDF Kit"),
new TextBlock("PDF يخلق وثائق
Apitron PDF KIT"),
new TextBlock("مرحبا بالعالم") // hello world
));
// add
grid to the document object
doc.Add(grid);
//
generate PDF document
using (Stream fs = File.Create("output.pdf"))
{
doc.Write(fs, new ResourceManager());
}
}
}
This code sample uses FlowLayout API to create the document,
but RTL and BIDI are supported by the FixedLayout API as well. Complete project is available on github.
The image below demonstrates the resulting document:
Pic. 1 RTL and BIDI text in PDF document
|
You can see that Arabic text in both BIDI and RTL columns is
written correctly.
Conclusion
Apitron PDF Kit for .NET
component is flexible enough to handle any text manipulation task with the
power of its unique PDF processing engine. In addition to PDF docs creation, it
supports text searching in bidi and rtl documents, and implements advanced font
substitution and resolution algorithms.
Downloadable version of this article can be found by the following link [PDF].
Downloadable version of this article can be found by the following link [PDF].
No comments:
Post a Comment