Articles in this section
Category / Section

How to draw complex script text (Arabic, Hindi, and Tamil) in a PDF Document?

2 mins read

The Syncfusion Essential® PDF is a feature-rich and high-performance .NET PDF library used to create, read, and edit PDF documents programmatically without Adobe dependencies. Using this library, you can draw complex script text such as Arabic, Hindi, Tamil, and more in a PDF document using C#.

Steps to draw the complex script text in a PDF document programmatically:

  1. Create a new console application project.Screenshot (1337).png
  2. Install the Syncfusion.Pdf.Net.Core NuGet package as a reference to your console application from Nuget.org.
    Screenshot (1339).png
  3. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Drawing;
  1. Use the following code sample in Program.cs to draw the complex script text in a PDF document.

C#

//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page.
PdfPage page = document.Pages.Add();
//Initialize the PDF page graphics.
PdfGraphics graphics = page.Graphics;
// Open a file stream.
FileStream fontStream = new FileStream(@"../../../NirmalaB.ttf", FileMode.Open, FileAccess.Read);
// Create a PdfTrueTypeFont object.
PdfFont font = new PdfTrueTypeFont(fontStream, 14);
FileStream arabicFontStream = new FileStream(@"../../../arial.ttf", FileMode.Open, FileAccess.Read);
// Create a PdfTrueTypeFont object.
PdfFont arabicFont = new PdfTrueTypeFont(arabicFontStream, 14);
// Create a PdfStringFormat object for text formatting.
PdfStringFormat format = new PdfStringFormat();
// Enable complex script support for the string format.
format.ComplexScript = true;

//Draw the Tamil text to page graphics. 
graphics.DrawString("பேசுதல்", font, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);

//Draw the Hindi text to page graphics. 
graphics.DrawString("मेरा नाम है दिनेश", font, PdfBrushes.Black, new RectangleF(0, 50, page.GetClientSize().Width, page.GetClientSize().Height), format);

//Draw the Arabic text to page graphics. 
graphics.DrawString("مرحبا", arabicFont, PdfBrushes.Black, new RectangleF(0, 100, page.GetClientSize().Width, page.GetClientSize().Height), format);

//Creating the stream object.
MemoryStream stream = new MemoryStream();
//Save the PDF document to stream.
document.Save(stream);
// Write the content of the memory stream to an output PDF file.
File.WriteAllBytes("Output.pdf", stream.ToArray());
//Close the document.
document.Close(true);

A complete working sample can be downloaded from Add_complex_script_text_in_PDF.zip.

By executing the program, you will get the PDF document as follows.Screenshot (1387).png

Take a moment to peruse the documentation for working with Text, where you can find the other options like drawing right-to-left text, multicolumn text, consuming TrueType fonts, Standards fonts, and CJK fonts.

Click here to explore the rich set of Syncfusion Essential® PDF features.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied