Hello,
I am using Syncfusion PDF to create a PDF with Urdu Language (RightToLeft). I am using Urdu Font ( Jameel Noori Nastaleeq Kasheeda.ttf) which is a .ttf font but the urdu text is not printing. Please see my code below:
PdfDocument doc = new PdfDocument();
PdfPage page = doc.Pages.Add();
PdfGraphics graphics = page.Graphics;
string path = Server.MapPath("~/fonts/Jameel Noori Nastaleeq Kasheeda.ttf");
PdfFont font = new PdfTrueTypeFont(@Server.MapPath("~/fonts/Jameel Noori Nastaleeq Kasheeda.ttf"), 24);
PdfStringFormat format = new PdfStringFormat();
format.TextDirection = PdfTextDirection.RightToLeft;
graphics.DrawString("ماہانہ رپورٹ فارم مجلس انصاراللہ جرمنی", font, PdfBrushes.Black, new RectangleF(100, 50, page.GetClientSize().Width, page.GetClientSize().Height), format);
doc.Save("C:\\temp\\RTLText.pdf");
doc.Close(true);
Process.Start("C:\\temp\\RTLText.pdf");
Can you help me with this?
Thanks and Regards
Hamid
We have investigated the reported issue with the provided details on our end and have successfully reproduced it. We recommend enabling the complex script property to ensure properly. Please find the code snippet attached for your reference.
PdfStringFormat format = new PdfStringFormat(); format.ComplexScript = true; format.TextDirection = PdfTextDirection.RightToLeft; graphics.DrawString("ماہانہ رپورٹ فارم مجلس انصاراللہ جرمنی", font, PdfBrushes.Black, new RectangleF(100, 50, page.GetClientSize().Width, page.GetClientSize().Height), format); |
Please refer to the documentation for more details.
Class PdfStringFormat - API Reference (syncfusion.com)
How to draw the complex scripts in a PDF document? | Syncfusion
Thanks for the help, it really helped. However, there are still some characters not visible even if I use the
format.ComplexScript = true
For example:
graphics.DrawString("قیادت تجنید ", font, PdfBrushes.Black, new RectangleF(100, 50, page.GetClientSize().Width, page.GetClientSize().Height), format);
If I use this string to print, only one word is printed and other is ignored.
Any help would be really helpful.
Thanks and Regards
Hi Hamid,
We were able to reproduce the reported issue with the provided details on our end, and currently, we are analyzing it. We will update you with further details on February 15th, 2024.
Regards,
Jeyalakshmi T
Currently we are still analyzing on your requirement, and we will update further details on February 19th, 2024.
After conducting a more thorough analysis, we found that we don't have a separate font rendering engine for Urdu text. Instead, it's using the Arabic script for rendering, which is causing issues with specific texts. As a result, there's improper preservation of text. To resolve this, we recommend using a supported font for rendering Hindi text in the PDF. You can utilize the Tahoma .ttf font, and the text will be rendered properly. Below is a code snippet demonstrating how to achieve this:
//Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page to the document PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page PdfGraphics graphics = page.Graphics; FileStream fontStream = new FileStream("tahoma.ttf", FileMode.Open, FileAccess.Read); //Create a new PDF font instance PdfFont pdfFont = new PdfTrueTypeFont(fontStream, 10); //Set the format for string PdfStringFormat format = new PdfStringFormat(); //Set the format as complex script layout type format.ComplexScript = true; //Draw the text graphics.DrawString("สวัสดีชาวโลก", pdfFont, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
//Save the PDF document MemoryStream stream = new MemoryStream(); doc.Save(stream); //Close the PDF document doc.Close(true); |
Thanks for the reply. I have tried it also but it doesn't show the font as it is with the Urdu font (in Word or HTML). Could you add support for Urdu fonts as well?
Thanks and Regards
Hi Hamid,
Word to PDF:
We suspect that your requirement is to maintain Urdu font during Word to PDF conversion. You can install the Urdu font on your local machine to ensure that the content is preserved properly during Word to PDF conversion. Additionally, you can use the SubstituteFont event to identify the missing font in your production environment and use an alternate font without installing it on your local machine.
You can refer to the Knowledge Base to resolve any font-related issues during Word to PDF/Image conversion.
HTML to PDF:
Blink rendering engine internally using a chrome headless browser for converting HTML to PDF. It will preserve the PDF document like how the input HTML/URL is displayed in chromium-based web browsers (chrome, print preview). The same behavior as replicates in our converter. However, we have attached the sample for your reference.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Urdu_HTMLtoPDF75179614
Output: https://www.syncfusion.com/downloads/support/directtrac/general/pd/HTML-to-PDF-Urdu-15276130
Please more about HTML converter in below link,
https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/features#html-string-to-pdf
Regards,
Jeyalakshmi T