# Write Arabic text in a PDF in C#

> Draw Arabic and other right to left text in a PDF in .NET with joined letters, bidi ordering and searchable text. MIT licensed, pure C#.

Available since 1.1.

Write a right to left paragraph with an embedded Arabic font, numbers and currency included.

## Short answer

Load a font that covers Arabic with `PdfOpenTypeFont.Load`, put the text in a `PdfParagraph` with
`Direction = PdfTextDirection.RightToLeft`, and draw it with `DrawText`. Letters join and take their
contextual forms, and the text carries ActualText, so it copies and searches in logical order.

```csharp title="recipe-arabic-text-pdf.cs"
#:package PdfNetStack@1.2.0
using PdfNetStack;
using PdfNetStack.Drawing;
using PdfNetStack.Fonts;

PdfFont arabic = PdfOpenTypeFont.Load("fonts/NotoSansArabic-Regular.woff2");   // embedded as a subset
PdfFont latin = PdfOpenTypeFont.Load("fonts/Inter-Regular.woff2");
var style = new PdfTextStyle(arabic, 20) { Fallbacks = [latin] };               // digits and the euro sign

PdfDocument doc = PdfDocument.Create();
PdfPage page = doc.Pages.Add(PdfRectangle.A4);
using (PdfGraphics g = page.CreateGraphics())
{
    var paragraph = new PdfParagraph { Direction = PdfTextDirection.RightToLeft, LineHeight = 1.6 }
        .Add("المبلغ المستحق: 1,250.00 € خلال ثلاثين يوما من تاريخ الفاتورة.", style);
    g.DrawText(paragraph, 60, 60, page.Width - 120);   // top left corner and width
}
doc.Save("arabic.pdf");

Console.WriteLine(PdfDocument.Open("arabic.pdf").Pages[0].ExtractText());   // logical order
```

![An Arabic sentence drawn right to left at the top of a page](https://www.jadev-corp.com/previews/recipe-arabic.webp)

## Notes

- The font is embedded as a subset of the glyphs drawn. TrueType, OpenType, WOFF and WOFF2 files
  load the same way.
- A font that lacks some characters, such as Latin letters, digits or the euro sign, borrows them
  from the fonts in `Fallbacks` on the `PdfTextStyle`, as the sample does with Inter.
- Numbers keep their left to right order inside the right to left line, as the Unicode
  bidirectional algorithm places them.
- `doc.Viewer.RightToLeft = true` tells viewers the document reads right to left, which sets the
  order of pages shown side by side.

## Related

- [Fonts and text](https://www.jadev-corp.com/guides/fonts-and-text/)
- [Extract text](https://www.jadev-corp.com/guides/extract-text/)
- API: [PdfParagraph](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfparagraph/), [PdfTextStyle](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdftextstyle/), [PdfOpenTypeFont](https://www.jadev-corp.com/api/pdfnetstack-fonts/pdfopentypefont/)

Source: https://www.jadev-corp.com/pdfnetstack/recipes/arabic-text-pdf/
