How to embed a Font in a PDF with RDLC

Posted on

Problem :

i am using Microsoft.Reporting.WebForms.LocalReport to generate some PDF, everything works like a charm, but now evil marketing wants to use a custom font (they are using such crazy arguments as “corporate identity” and stuff).

i already goggled around and now i know that

  • i need ReportViewer 2008 SP1 or greater
  • the font has to be marked as embedding allowed
  • the font has to be TrueType

but it still doesn’t work.
i belief that RDLC does not support this feature, does anybody know if this is the case?
unfortunately i cant use Server-side reports cause i am lacking a Reporting Server.


Solution :

Embedding font’s works with Microsoft Reporting 2010 or later the following restrictions still apply

  • Font must be marked as embedding allowed
  • Font must be of type TrueType

You may experience the problem that your Font is getting embedded but your PDF still displays text in Arial. This happened to me after i installed some new fonts on a Windows Server 2008 R2, restarting the AppPool (ASP.NET MVC) did not solve this Problem, a Server restart was needed.

I’ve done a simple test using Arial Narrow font with Visual Studio 2008 and it worked fine.
I’ve tested the generated PDF on virtual XP machine that doesn’t have the font and it rendered ok.
Perhaps it’s a problem with the font?

Hmm, perhaps it’s this – in my test I’ve used Winforms.LocalReport not WebForms. Perhaps that’s the trick?

I was having the same problem, but I’ve found that the font doesn’t need to be embedded. The problem was with the Font Face attribute in the HTML. The HTML editor we were using generated the Font tag like this:

<font face="Impact,Charcoal,sans-serif" size="6">Impact </font>

Which was fine for the Report Viewer, but to produce a PDF file, it needed to look like this:

<font face="Impact" size="6">Impact </font>

So I added code to replace the the attribute values before it was bound to the report:

htmlValue = htmlValue.Replace("Impact,Charcoal,sans-serif", "Impact")
               .Replace("Arial,Helvetica,sans-serif", "Arial")
               .Replace("Georgia,serif", "Georgia")
               .Replace("Verdana,Geneva,sans-serif", "Verdana")
               .Replace("'Courier New',Courier,monospace", "Courier New")
               .Replace("'Lucida Console',Monaco,monospace", "Lucida Console")
               .Replace("Tahoma,Geneva,sans-serif", "Tahoma")
               .Replace("'Times New Roman',Times,serif", "Times New Roman")
               .Replace("'Trebuchet MS',Helvetica,sans-serif", "Trebuchet MS");

  • Font must be marked as embedding allowed
  • Font must be of type TrueType
  • Add your font to windows server fonts

If you do all of the above and font does not show in Pdf report RDLC file,

Maybe you must restart server , it does work for me

To add to the great answer by marc.d, I can confirm that in my case I also had to restart the server entirely. I’d also add that the way to check if a font is embeddable or not is to do one of the two methods I’ve described below.

Method 1) If your font is already installed

In Windows Explorer browse to C:WindowsFonts, and find the font you are interested in. Note that fonts in the same family will be grouped together, so you need to double click on a group to be able to navigate to an individual font file. In the properties list at the bottom of the Explorer window you’ll see ‘Embeddability’:
enter image description here

Method 2) If you have the TTF file in some other location

Using Windows Explorer, open the file Properties and switch to the Details tab:
enter image description here

The possible values you might see for a font are:

  • No embedding—The font supplier does not allow embedding. These fonts are quite rare.
  • Print and preview—The font supplier allows for embedding but the document is locked and cannot be edited. Most third-party fonts have this setting.
  • Editable—The font supplier allows the font to be embedded within a document and allows the document to be edited using that embedded font
  • Installable—This is the most permissive setting. The font supplier allows the font to be embedded within a document, and permits the document viewing application to permanently install the font on the user’s computer. Most applications treat these fonts like those set to Editable embedding.


Leave a Reply

Your email address will not be published. Required fields are marked *