iText pdfCalligraph
pdfCalligraph is an iText Core add-on for Java and C# (.NET) that allows you to unlock advanced typographic features in PDF. It also allows you to expand your document workflow with global languages and writing systems, that incorporate accurate rendering and are suitable for data processing.
Supported Scripts
Language | Script | Module |
Arabic, Persian, Kurdish, Azerbaijani, Sindhi, Pashto, Lurish, Urdu, Mandinka, Punjabi and others | ARABIC | pdfCalligraph |
Hebrew, Yiddish, Judaeo-Spanish, and Judeo-Arabic | HEBREW | pdfCalligraph |
Bengali, Assamese | BENGALI | pdfCalligraph |
Hindi, Sanskrit, Pali, Awadhi, Bhojpuri, Braj Bhasha, Chhattisgarhi, Haryanvi, Magahi, Nagpuri, Rajasthani, Bhili, Dogri, Marathi, Nepali, Maithili, Kashmiri, Konkani, Sindhi, Bodo, Nepalbhasa, Mundari and Santali | DEVANAGARI, NAGARI | pdfCalligraph |
Gujarati and Kutchi | GUJARATI | pdfCalligraph |
Punjabi | GURMUKHI | pdfCalligraph |
Kannada, Konkani and others | KANNADA | pdfCalligraph |
Khmer (Cambodia) | KHMER | pdfCalligraph |
Malayalam | MALAYALAM | pdfCalligraph |
Mayanmar | MAYANMAR (MON-BURMESE) | pdfCalligraph |
Odia | ORIYA | pdfCalligraph |
Tamil | TAMIL | pdfCalligraph |
Telugu (Dravidian language) | TELUGU | pdfCalligraph |
Thai | THAI | pdfCalligraph |
Chinese | Core | |
Japanese | Core | |
Korean | Core | |
WESTERN | Core | |
Russian, Ukrainian, Belarussian, Bulgarian and others | CYRILLIC | Core |
Greek | GREEK | Core |
Armenian | ARMENIAN | Core |
Georgian | GEORGIAN | Core |
How it works
For this example, we'll demonstrate using pdfCalligraph to correctly render text in different languages. First, let’s start with a simple English sentence, which we've translated into three different languages using Google Translate.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
final String[] sources = {"english.xml", "arabic.xml", "hindi.xml", "tamil.xml"};
final PdfWriter writer = new PdfWriter(DEST);
final PdfDocument pdfDocument = new PdfDocument(writer);
final Document document = new Document(pdfDocument);
final FontSet set = new FontSet();
set.addFont("fonts/NotoNaskhArabic-Regular.ttf");
set.addFont("fonts/NotoSansTamil-Regular.ttf");
set.addFont("fonts/FreeSans.ttf");
document.setFontProvider(new FontProvider(set));
document.setProperty(Property.FONT, new String[]{"MyFontFamilyName"});
for (final String source : sources) {
final File xmlFile = new File(source);
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = factory.newDocumentBuilder();
final org.w3c.dom.Document doc = builder.parse(xmlFile);
final Node element = doc.getElementsByTagName("text").item(0);
final Paragraph paragraph = new Paragraph();
final Node textDirectionElement = element.getAttributes().getNamedItem("direction");
boolean rtl = textDirectionElement != null && textDirectionElement.getTextContent()
.equalsIgnoreCase("rtl");
if (rtl) {
paragraph.setTextAlignment(TextAlignment.RIGHT);
}
paragraph.add(element.getTextContent());
document.add(paragraph);
}
document.close();
pdfDocument.close();
writer.close();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
string[] sources = new string[] { "english.xml", "arabic.xml", "hindi.xml", "tamil.xml" };
PdfWriter writer = new PdfWriter(DEST);
PdfDocument pdfDocument = new PdfDocument(writer);
Document document = new Document(pdfDocument);
FontSet set = new FontSet();
set.AddFont("NotoNaskhArabic-Regular.ttf");
set.AddFont("NotoSansTamil-Regular.ttf");
set.AddFont("FreeSans.ttf");
document.SetFontProvider(new FontProvider(set));
document.SetProperty(Property.FONT, new String[] { "MyFontFamilyName" });
foreach (string source in sources)
{
XmlDocument doc = new XmlDocument();
var stream = new FileStream(source, FileMode.Open);
doc.Load(stream);
XmlNode element = doc.GetElementsByTagName("text").Item(0);
Paragraph paragraph = new Paragraph();
XmlNode textDirectionElement = element.Attributes.GetNamedItem("direction");
Boolean rtl = textDirectionElement != null && textDirectionElement.InnerText.Equals("rtl");
if (rtl)
{
paragraph.SetTextAlignment(TextAlignment.RIGHT);
}
paragraph.Add(element.InnerText);
document.Add(paragraph);
}
document.Close();
Input
Output
Resources
Here you will find the necessary resources to install and use pdfCalligraph.
Other resources
Core capabilities of iText pdfCalligraph
Off-the-shelf PDF creators have problems with character interactions or writing systems such as Arabic, Hebrew, Hindi or Thai and in regards to kerning, ligatures, and glyph substitutes. pdfCalligraph handles all those writing systems with ease, and by making use of OpenType features it opens up the full range of iText PDF functionalities for you in your language, and your writing system. This even includes text extraction for writing systems with compound characters. Another advantage of pdfCalligraph is that you do not have to adjust your programming in Java or .NET (C#).
Leverage advanced font features
Such as OpenType features, kerning, ligatures and glyph substitutes.
Transparent support for many languages
Including languages that use Brahmic, Arabic and Hebrew scripts as well as Thai and many more.
Automatic detection of language/writing system
Required font features are enabled and applied automatically. Manual configuration is possible. pdfCalligraph integrates seamlessly with iText Core and pdfHTML.
Typographic alignment for all writing systems
Flush left, flush right, centered and justified alignment.
Why use iText pdfCalligraph?
pdfCalligraph opens up a world of possibilities, allowing you to service businesses on all Continents. Wherever you or your business are based, pdfCalligraph opens up the full capability of our PDF functionalities to you, in your local language and your writing system.
Supporting your international business
Use your document processes for multiple languages without having to adjust your PDF programming. Exchange non-proprietary data format between users of many cultures. Create large batches of PDF documents in various writing systems, or be finally able to produce and manipulate PDF documents in your own local language and writing system while retaining all the PDF processing functionalities iText has to offer.
Automatic detection of writing systems in PDF
Detect which writing system is being used in PDF creation. Make glyph substitutions based on script- and font-specific information. pdfCalligraph also lets you add information about the reading order, such as Arabic which is read from right to left. pdfCalligraph automatically detects and manages the writing system of Arabic, Hebrew, Hindi or Thai and many more with ease.