hany mohamed

hany mohamed

  • 1.6k
  • 109
  • 3.7k

Can't display arabic word in razor pages when export to pdf

May 9 2024 8:34 PM
public IActionResult OnPostGeneratePDF() 
{ 
// Get invoice information from form 
string invoiceNumber = Request.Form["InvNo"]; 
string invoiceDate = Request.Form["InvDate"]; 
// Create PDF document 
using (MemoryStream memoryStream = new MemoryStream()) 
{ 
Document document = new Document(); 
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream); 
document.Open(); 
// Font settings for Arabic text 
BaseFont baseFont = BaseFont.CreateFont("c:\\windows\\fonts\\times.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); 
Font arabicFont = new Font(baseFont, 12, Font.NORMAL); 
// Add Arabic text to PDF 
Paragraph paragraph = new Paragraph("??? ????????: " + invoiceNumber, arabicFont); document.Add(paragraph); 
paragraph = new Paragraph("????? ????????: " + invoiceDate, arabicFont); 
document.Add(paragraph); 
// Add company name, item names, item prices, total price, etc. as needed 
document.Close(); 
// Export PDF 
return File(memoryStream.ToArray(), "application/pdf", "invoice.pdf"); 
} 
} 
} 
}

it cames like this in the PDF file :???????? ???


Answers (3)