Data table to PDF with Dubai (Arabic) font using iTextSharp not working in Console Application

Last Reply 5 months ago By dharmendr

Posted 5 months ago

Dear,

I am facing one issue with ITextSharp Dubai font, I tried with the sample code its working fine but the individual character is not showing in the pdf file

eg: the sentence الخطة التشغيلية لمبادرة دراية لعام 2020 م ignore the character "م" or any another single character. Kindly guide me how to resolve this issue.

Can you please create a console application using Dubai font.

Font download link : https://dubaifont.com/download

PdfPTable hedertable = new PdfPTable(new float[] { 20, 60, 20 });
BaseFont bf1 = BaseFont.CreateFont(Server.MapPath("/fonts/") + "Dubai-Regular.ttf",BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
string cellTextm = "الخطة التشغيلية لمبادرة دراية لعام" + thisDay + "م";
iTextSharp.text.Font fontheader = new iTextSharp.text.Font(bf1, 20, iTextSharp.text.Font.NORMAL);
iTextSharp.text.pdf.PdfPCell mcell = new iTextSharp.text.pdf.PdfPCell(new Phrase(16, cellTextm, fontheader))
{ HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER };
mcell.VerticalAlignment = Element.ALIGN_MIDDLE;
mcell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
hedertable.AddCell(mcell);
//Create PDF
Document pdfDoc = new Document(PageSize.A4.Rotate(), 10f, 10f, 10f, 10f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
pdfDoc.Add(hedertable);
pdfDoc.Add(table);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();

 

Results 1 - 5 of 7 12
Posted 5 months ago
Hi @sajeerma,
Please try the following

[Solved] Column Header not displaying while exporting DataTable to PDF using iTextSharp in ASP.Net

It might help you.

Cheers Andrea.

Posted 5 months ago

Thank you for your quick reply. I have problem with only Dubai font, rest of the Arabic font is working fine with me, unfortunately my organization using Dubai font for all documents.

Issue for Dubai font Individual character only. Like "م" , "س" etc. more than one character word is working fine sample in english if I write "An Apple a day!" the character 'a' is not showing inside the pdf file.



Posted 5 months ago

Dear dharmendr,

 

I am facing issue with Dubai font only.

 

Thank you


Posted 5 months ago

Hi sajeerma,

Use ARIALUNI.TTF font. Refer below code.

There might be the issue with the font Dubai font or it is not supported in iTextSharp.

PdfPTable hedertable = new PdfPTable(1);
BaseFont bf1 = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\ARIALUNI.TTF", BaseFont.IDENTITY_H, true);
string cellTextm = "الخطة التشغيلية لمبادرة دراية لعام" + " 2020 " + "م";
iTextSharp.text.Font fontheader = new iTextSharp.text.Font(bf1, 20, iTextSharp.text.Font.NORMAL);
iTextSharp.text.pdf.PdfPCell mcell = new iTextSharp.text.pdf.PdfPCell(new Phrase(16, cellTextm, fontheader))
{ HorizontalAlignment = iTextSharp.text.Element.ALIGN_TOP };
mcell.VerticalAlignment = Element.ALIGN_TOP;
mcell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
mcell.Border = 0;
hedertable.AddCell(mcell);
        
//Create PDF
Document pdfDoc = new Document(PageSize.A4.Rotate(), 10f, 10f, 10f, 10f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
pdfDoc.Add(hedertable);
//pdfDoc.Add(table);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.Write(pdfDoc);
Response.End();