0

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("₹");
skywalker2909
  • 1,636
  • 2
  • 31
  • 46

2 Answers2

1

I tried the HelloWorld MigraDoc sample, just changed the line const bool unicode = true; to true (was false) and added some Rupee signs to this line paragraph.AddFormattedText("Hello, World! ₹₹₹", TextFormat.Bold);.

It worked as expected.

Please note that MigraDoc uses the Verdana font by default. To see the Rupee sign, MigraDoc has to use a font that has the Rupee sign. With older Windows versions you will have to use another font, not Verdana.

Remarks on Neville's answer: you do not have to use XPrivateFontCollection if you use fonts that are installed on the computer. If a program is deployed to many computers, XPrivateFontCollection can be used to avoid installing fonts on all those computers. If you use a program only on one computer, just install the font and use it without the font collection.

  • Hi Thomas, thanks for your help ! appreciate it ! well i am using the XPrivateFontCollection because in my case there is a deployment on multiple machines and secondly i had to set the Unicode property to false, because not all machines will be having the Unicode support. Thanks! – skywalker2909 Nov 10 '14 at 06:45
-1

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

skywalker2909
  • 1,636
  • 2
  • 31
  • 46
  • 2
    That is really not a good solution. All this font does is replacing the *image* of the grave accent (not the tilde, as you and the web page say) with one for the Rupee character. That is a real problem, as you can see in various places -- first off, try to copy that text out of your PDF. Also, composed characters such as `egrave` and `ograve` now show the Rupee symbol as well. – Jongware Nov 07 '14 at 10:59
  • I tried copying the symbol out of my pdf, pasted it in a notepad file and it still shows properly ! – skywalker2909 Nov 07 '14 at 12:47
  • That used the same font? – Jongware Nov 07 '14 at 14:05
  • Yes, since i have installed the downloaded font in Windows, so whenever i press the tilde key , it prints that symbol now instead of the tilde, and if i want the tilde back again, i have to uninstall that downloaded font, i know its not an optimal solution but thats what is working for me so far! – skywalker2909 Nov 07 '14 at 14:07