We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

how to draw a Arabic text on pdf page?

Hi I am trying to use SyncfusionGraphics.PdfTextElement to draw a Arabic text(سیتوژنتیک_) on pdf page, but all of the chars become to question marks,so how to draw a Arabic text on pdf page? below is my code:

Syncfusion.Pdf.Graphics.PdfStringFormat format = new Syncfusion.Pdf.Graphics.PdfStringFormat();
format.Alignment = Syncfusion.Pdf.Graphics.PdfTextAlignment.Left;
SyncfusionGraphics.PdfTextElement text = new SyncfusionGraphics.PdfTextElement()
        {
            "سیتوژنتیک"
            Font = font,
            StringFormat = format,
            Brush = this.GetPdfBrush(textBlockInfo.FontColor)
        };
       
    text.Draw(page, position,
                 page.Size.Width - page.Section.PageSettings.Margins.Left - page.Section.PageSettings.Margins.Right, layoutFormat);


5 Replies

GM Geetha M Syncfusion Team June 8, 2012 04:27 AM UTC

Hi Steven,

Thank you for your interest in Syncfusion products.

I am afraid that I was not able to reproduce the problem when drawing Arabic text with embedded font. I had placed the code snippet in the below:

PdfDocument document = new PdfDocument();
PdfPage page = document.Pages.Add();

PdfStringFormat format = new PdfStringFormat();
format.Alignment = PdfTextAlignment.Left;

PdfTextElement text = new PdfTextElement();
text.Text = "سیتوژنتیک";
text.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true);
text.StringFormat = format;
text.Brush = PdfBrushes.Black;

text.Draw(page, PointF.Empty);

document.Save("Sample.pdf");
document.Close(true);

Could you please try this and let me know if you still see the problem?

Regards

Geetha


SH Steven Hongbin Zhou June 21, 2012 04:32 AM UTC

Hi Geetha

I tried your source code, the Arabic text display. But when I use below test case, the chars "基因遗传学" was lost, do you know how to resolve this issue?

 PdfDocument document = new PdfDocument();
            PdfPage page = document.Pages.Add();

            PdfStringFormat format = new PdfStringFormat();
            format.Alignment = PdfTextAlignment.Left;

            PdfTextElement text = new PdfTextElement();
            text.Text = "559_XXXXXRegionsOfInterestسیتوژنتیک基因遗传学_.hg19.bed";
            text.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true);
            text.StringFormat = format;
            text.Brush = PdfBrushes.Black;
            text.Draw(page, PointF.Empty);
            document.Save("Sample.pdf");
            document.Close(true);

The attachment file is my test restult.

Thanks
Steven


Sample_7e969cd3.zip


GM Geetha M Syncfusion Team June 22, 2012 08:59 AM UTC

Hi Steven,

Thank you for the details.

It appears that Chinese characters cannot be displayed using "Arial" font in Adobe. To draw both Arabic and Chinese texts, please make use of "Arial Unicode MS" font or other equivalent font. Here is the code snippet.

text.Text = "559_XXXXXRegionsOfInterestسیتوژنتیک基因遗传学_.hg19.bed";
text.Font = new PdfTrueTypeFont(new Font("Arial Unicode MS", 10f), true);

Please try this and let me know if you have any questions.

Regards
Geetha


AA Ajimon Anirudhan April 28, 2023 12:25 PM UTC

Hi Geetha

I am using Syncfusion.Xamarin.Pdf 20.2.0.50.

As you have mentioned above ,

text.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true);  is not supporting .
Can you help me to drow arabic string in my pdf document 




GK Gowthamraj Kumar Syncfusion Team May 1, 2023 01:20 PM UTC

We can draw the Arabic text with right-to-left (RTL) format in a PDF document in Xamarin Platform. We have to embed the font files in Xamarin Forms application by setting the build action to embedded resource. Please follow the below steps in your end and let us know if it is suites your requirement or not,


  • Include the supported font file into the Assets folder.
  • Right click the font file and Go to properties and Set Build Action to Embedded resource and copy always


Please find the below screenshot,



Note: Please make sure the using font file should supports the Arabic text or not. We have to use the supported font file to preserve the text properly.


Please refer the below link for more information,

https://www.syncfusion.com/blogs/post/adding-rtl-support-to-your-pdf-in-xamarin.aspx

https://support.syncfusion.com/kb/article/8560/how-to-draw-unicode-characters-in-a-pdf-in-xamarin

We have attached the simple sample to draw a Arabic and English text for your reference, please try the sample on your end and let us know the result.


Loader.
Live Chat Icon For mobile
Up arrow icon