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.
classProgram
{
staticvoid Main(string[] args)
{
// create flow document
FlowDocument doc = newFlowDocument()
{
Margin = newThickness(10)
};
// register style for grid rows
doc.StyleManager.RegisterStyle("gridrow", newStyle()
{
Font = newFont("Traditional Arabic", 20),
Align = Align.Center
});
// register style for header row
doc.StyleManager.RegisterStyle("gridrow.header",newStyle()
{
Background = RgbColors.Gray,
Color = RgbColors.White,
Font = newFont(StandardFonts.Helvetica, 20)
});
// create grid
Grid grid = newGrid(150,Length.Auto, 150);
// add header row
grid.Add(newGridRow(newTextBlock("LTR"),newTextBlock("BIDI"),
newTextBlock("RTL")){Class = "header"});
// add content row
grid.Add(newGridRow(
newTextBlock("Apitron PDF Kit"),
newTextBlock("PDF يخلقوثائقApitron PDF KIT"),
newTextBlock("مرحبابالعالم") // hello world
));
// add grid to the document object
doc.Add(grid);
// generate PDF document
using (Stream fs = File.Create("output.pdf"))
{
doc.Write(fs, newResourceManager());
}
}
}
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 .NETcomponent 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.