- Home
- Forum
- Xamarin.Forms
- Arabic text do not appear when string Alignment RightToLeft
Arabic text do not appear when string Alignment RightToLeft
Hello Syncfusion, I am trying to use SyncfusionGraphics.PdfTextElement to draw a Arabic text( توفير خدمات التمثيل التجاري هدفها زيادة رقم اعمال الشركة. ) on pdf page, but all of the text do not appear (Blank page) when i set The
TextDirection
to RightToLeft ,so how to draw a Arabic text on pdf page? below is my code:
Note Im using Android API29
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a new PDF page.
PdfPage page = document.Pages.Add();
//Create new PdfTrueTypeFont instance.
//Load the font from assets.
Stream fontStream = typeof(App).GetTypeInfo().
Assembly.GetManifestResourceStream
("BrokerApp.Fonts.Arial.ttf"); PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 22);
//Create a PdfStringFormat.
PdfStringFormat format = new PdfStringFormat();
//Set text direction.
format.TextDirection = PdfTextDirection.RightToLeft;
//Set text alignment.
format.Alignment = PdfTextAlignment.Right;
//format.Alignment = PdfTextAlignment.Left;
PdfTextElement text = new PdfTextElement();
text.Text = "بالعالم مرحبا !";
text.Font = new PdfTrueTypeFont(fontStream, 15);
text.StringFormat = format;
text.Brush = PdfBrushes.Black;
text.Draw(page, PointF.Empty);
//Save document.
MemoryStream ms = new MemoryStream();
document.Save(ms);
//Close the PdfDocument instance.
document.Close(true);
//BrokerApp.Fonts.Arial.ttf
Xamarin.Forms.DependencyService.Get<ISave>().SaveAndView("Text.pdf", "application/pdf", ms);
SIGN IN To post a reply.
1 Reply
GK
Gowthamraj Kumar
Syncfusion Team
December 6, 2021 02:02 PM UTC
Hi Abdel,
Thank you for contacting Syncfusion support.
We can draw the Arabic text with right-to-left (RTL) format in a PDF document by using DrawString method of PdfGraphics class in Xamarin Platform. Please refer the below code snippet to draw Arabic RTL text in Xamarin and let us know the result,
|
string text = "بالعالم مرحبا !";
PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 12);
//Create a PdfStringFormat.
PdfStringFormat format = new PdfStringFormat();
//Set text direction.
format.TextDirection = PdfTextDirection.RightToLeft;
//Set text alignment.
format.Alignment = PdfTextAlignment.Right;
SizeF pageSize = page.GetClientSize();
//Draw text to the PDF document.
page.Graphics.DrawString(text, font, PdfBrushes.Black, new Syncfusion.Drawing.RectangleF(0, 0, pageSize.Width, pageSize.Height), format);
|
Please find the output document from below,
Please refer the below link for more information,
Please let us know if you need any further assistance with this.
Regards,
Gowthamraj K
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
AK Abdel khalek
- Dec 3, 2021 04:38 PM UTC
- Dec 6, 2021 02:02 PM UTC