Search code examples
c#pdfpdf-generationpdfsharpmigradoc

Unable to generate the rupee symbol (₹) using MigraDoc for C#


In the code snippet below, i am trying to embed the rupee symbol in the generated pdf document, but the pdf is rendering it as a square box instead of the symbol.

Using MigraDoc, i have set the unicode property to 'true' and fontembedding to 'always', but it still does not work. Can anyone help me out with a solution to this?

string value = "1000";          

dataRow.Cells[4].AddParagraph("₹");

Solution

  • Finally figured out a way for this , below is my solution for all those who are also facing the same problem:

    1. Download and install the Rupee Font here

    2. Next, set it as the default font in your Visual Studio project using these instructions

    3. Create a fonts folder in your Visual Studio and add the downloaded font in step 1.

    4. Now add the following code

      XPrivateFontCollection pfc = XPrivateFontCollection.Global;
      Uri myuri = new Uri(@"D:\Test                          
      Projects\SampleProjects\PdfGeneration\fonts\Rupee_Foradian.ttf");
      pfc.Add(myuri, "./#Rupee Foradian");
      
      double value = 1000;
      dataRow.Cells[4].Format.Font.Name = "Rupee Foradian";
      CultureInfo cinfo = new CultureInfo("hi-IN");
      NumberFormatInfo numinfo = cinfo.NumberFormat;
      numinfo.CurrencySymbol = "₹";
      
      dataRow.Cells[4].AddParagraph(value.ToString("C", numinfo)); 
      

    Note: To type the '₹" symbol, use the tilde key