8 Answers, 1 is accepted
Thank you for contacting us.
When you want to export custom font to PDF you should first register the font using the FontsRepository.
The following example shows how to register "MS Mincho" font family using a font file "msmincho.ttc" (the file should be added to your project and should have build action "Resource" in its properties).
public
const
string
CustomFontResource =
"Resources/msmincho.ttc"
;
public
static
readonly
FontFamily CustomFontFamily =
new
FontFamily(
"MS Mincho"
);
private
static
void
RegisterFont()
{
byte
[] fontData = ResourceHelper.GetResourceData(CustomFontResource);
FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Normal, FontWeights.Normal, fontData);
}
You should have in mind that using the FontsRepository requires you to add reference to Telerik.Windows.Documents.Fixed.dll. For more informations about fonts in PDF export you may follow this link to Fonts in PdfProcessing documentation article.
When you have registered the font you can further set the font family in worksheet's cells when generating the document. The following code snippet shows how to set the previously registered font family to cell A1:
worksheet.Cells[0, 0].SetFontFamily(
new
ThemableFontFamily(CustomFontFamily));
Following this steps you could export the PDF with the desired font.
I hope you find this helpful. If you have any other questions or concerns do not hesitate to contact us again.
Regards,
Deyan
the Telerik team

If I want to use the Chinese font that all the client pc have that, for example "Simsun" or "SimHei". Need I add the font file to the resource.
Thank you for contacting us.
To answer your questions:
- When you have registered some font in your silverlight project everyone who visits your web site will be able to see the content properly (there is no need to download this font locally on the client pc).
- Even if your client pc has some of the mentioned fonts locally, you will still have to register that font in your silverlight project (otherwise there will be issues with exporting PDF documents with this font).
I hope this is helpful. If you have additional questions do not hesitate to contact us again.
Regards,
Deyan
the Telerik team

I can not find GetResourceData method in the class ResourceHelper(Telerik.Windows.Controls.Charting),why?
byte[] fontData = ResourceHelper.GetResourceData(CustomFontResource);
The ResourceHelper class mentioned in previous code snippets should be implemented so that it can return the byte array of a resource file. Here follows a sample implementation of such class:
public static
class
ResourceHelper
{
public
static
Uri GetResourceUri(
string
resource)
{
AssemblyName assemblyName =
new
AssemblyName(
typeof
(ResourceHelper).Assembly.FullName);
string
resourcePath =
"/"
+ assemblyName.Name +
";component/"
+ resource;
Uri resourceUri =
new
Uri(resourcePath, UriKind.Relative);
return
resourceUri;
}
public
static
Stream GetResourceStream(
string
resource)
{
return
Application.GetResourceStream(ResourceHelper.GetResourceUri(resource)).Stream;
}
public
static
byte
[] GetResourceData(
string
resource)
{
using
(MemoryStream memoryStream =
new
MemoryStream())
{
ResourceHelper.GetResourceStream(resource).CopyTo(memoryStream);
return
memoryStream.ToArray();
}
}
}
In order to use ResourceHelper.GetResourceData() method you should first add the resource file in your project and set its build action as a "Resource".
I hope this is helpful.
Regards,
Deyan
the Telerik team
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Hei, i have problems displaying the font Gill Sans MT on the pdf export, it reverts to a default font.
It displays correctly in the radrichtextbox editor.
I have implented the following
FontFamily CustomFontFamily = new FontFamily("Gill Sans MT");
FontManager.RegisterFont(CustomFontFamily);
byte[] fontData = null;
FontFamily CustomFontFamily = new FontFamily("Gill Sans MT");
fontData = cResourceHelper.ResourceHelper.GetResourceData("Resources/Fonts/GIL_____.ttf");
FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Normal, FontWeights.Normal, fontData);
fontData = cResourceHelper.ResourceHelper.GetResourceData("Resources/Fonts/GILB____.ttf");
FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Normal, FontWeights.Bold, fontData);
fontData = cResourceHelper.ResourceHelper.GetResourceData("Resources/Fonts/GILBI___.ttf");
FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Italic, FontWeights.Bold, fontData);
fontData = cResourceHelper.ResourceHelper.GetResourceData("Resources/Fonts/GILC____.ttf");
FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Normal, FontWeights.Normal, fontData);
fontData = cResourceHelper.ResourceHelper.GetResourceData("Resources/Fonts/GILI____.ttf");
FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Normal, FontWeights.Bold, fontData);
fontData = cResourceHelper.ResourceHelper.GetResourceData("Resources/Fonts/GLSNECB.ttf");
FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Italic, FontWeights.Normal, fontData);
The fonts are extracted from the windows font folder under "Gill Sans MT"
and added to the project folder Resources/Fonts and build action as resource
Thank you for contacting us.
The FontsRepository class is used in PdfProcessing export to PDF. As RadSpreadProcessing and RadWordsProcessing libraries use PdfProcessing for their PDF export you may use FontsRepository class for registering fonts data when exporting PDFs with these two libraries as well.
However, RadRichTextBox control uses a completely different code for its PDF export and it does not provide functionality for embedding fonts. We have logged such feature request in our feedback portal. You can vote for it and follow its implementation progress by following this feedback item.
As a workaround for now you may use RadWordsProcessing for WPF to get PDF with "Gill Sans MT" font family in your Silverlight application through a web service. I am attaching a demo solution showing how exactly you can achieve that. A few words about the attached solution:
- It contains a Silverlight project called WordsProcessingRegisterFontsFromServiceDemo. This project has a single button that exports a PDF file containing the desired font family. The PDF file is received by a web service. This may be seen in ServiceClientGetPdfWithGillSansMTCompleted method.
- The second project is a web application called WordsProcessingRegisterFontsFromServiceDemo.Web. This project implements the web service that uses RadWordsProcessing for WPF to generate flow document containing "Gill Sans MT" font family and then exports it to PDF. This may be seen in WordsProcessingPdfService.svc.cs.
- The current implementation does not register the "Gill Sans MT" font family as the web application has access to the system fonts. However, if you are not sure that this font will be installed on the machine that runs the service you may still register the font using the FontsRepository as mentioned in your post.
- When you click on the button in the Silverlight application it simply exports the PDF file bytes previously received by the web service.
I hope this is helpful. If you have any other questions or concerns please do not hesitate to contact us again.
Regards,
Deyan
the Telerik team

Thanks for your answer.
have resolved it with a serverside service, however hope you can put priority on fixing this on the client side also