Skip to content

Commit cf9e4fd

Browse files
Merge pull request #397 from telerik/new-kb-inserting-special-symbols-pdf-radpdfprocessing-edb732d7e0be4da39da3676e06ecdab3
Added new kb article inserting-special-symbols-pdf-radpdfprocessing
2 parents be722b5 + e6ec105 commit cf9e4fd

File tree

4 files changed

+134
-2
lines changed

4 files changed

+134
-2
lines changed
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
title: Inserting Special Symbols in PDF using RadPdfProcessing
3+
description: This article explains how to insert special symbols, such as "↓", in a PDF document using RadPdfProcessing.
4+
type: how-to
5+
page_title: Inserting Special Symbols in PDF using RadPdfProcessing
6+
slug: inserting-special-symbols-pdf-radpdfprocessing
7+
tags: radpdfprocessing, pdf, special symbols, insert, visual studio
8+
res_type: kb
9+
---
10+
11+
## Environment
12+
| Version | Product | Author |
13+
| --- | --- | ---- |
14+
| 2024.1.124 | RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|
15+
16+
## Description
17+
18+
This article shows how to insert special symbols, such as "↓", in a PDF document using RadPdfProcessing.
19+
20+
![Special Symbols in PdfProcessing](images/inserting-special-symbols-pdf-radpdfprocessing.png)
21+
22+
## Solution
23+
24+
When using the Telerik Document Processing's .NET Standard assemblies/NuGet packages and want to export a document to PDF format, the PdfProcessing library needs to have access to the specific font's data so that it can read it and add it to the PDF file. That is why, to allow the library to create and use fonts, you will need to provide an implementation of the FontsProviderBase abstract class and set this implementation to the FontsProvider property of FixedExtensibilityManager.
25+
26+
```csharp
27+
28+
29+
using System.Diagnostics;
30+
using Telerik.Documents.Core.Fonts;
31+
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
32+
using Telerik.Windows.Documents.Fixed.Model;
33+
using Telerik.Windows.Documents.Fixed.Model.Editing;
34+
using Telerik.Windows.Documents.Fixed.Model.Editing.Tables;
35+
36+
Telerik.Windows.Documents.Extensibility.FontsProviderBase fontsProvider = new FontsProvider();
37+
Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.FontsProvider = fontsProvider;
38+
39+
RadFixedDocument document = new RadFixedDocument();
40+
RadFixedDocumentEditor editor = new RadFixedDocumentEditor(document);
41+
42+
Table table = new Table();
43+
TableRow row = table.Rows.AddTableRow();
44+
TableCell valueCell = row.Cells.AddTableCell();
45+
Block valueCellBlock = valueCell.Blocks.AddBlock();
46+
valueCellBlock.InsertText(new FontFamily("Arial"),"36 °C");
47+
row = table.Rows.AddTableRow();
48+
valueCell = row.Cells.AddTableCell();
49+
valueCellBlock = valueCell.Blocks.AddBlock();
50+
valueCellBlock.InsertText(new FontFamily("Calibri"), "");
51+
editor.InsertTable(table);
52+
53+
string outputdDocumentName = "Exported.pdf";
54+
if (File.Exists(outputdDocumentName))
55+
{
56+
File.Delete(outputdDocumentName);
57+
}
58+
59+
PdfFormatProvider provider = new PdfFormatProvider();
60+
using (Stream stream = new FileStream(outputdDocumentName, FileMode.OpenOrCreate))
61+
{
62+
provider.Export(document, stream);
63+
}
64+
65+
Process.Start(new ProcessStartInfo() { FileName = outputdDocumentName, UseShellExecute = true });
66+
67+
internal class FontsProvider : Telerik.Windows.Documents.Extensibility.FontsProviderBase
68+
{
69+
private readonly string fontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
70+
71+
public override byte[] GetFontData(Telerik.Windows.Documents.Core.Fonts.FontProperties fontProperties)
72+
{
73+
string fontFamilyName = fontProperties.FontFamilyName;
74+
bool isBold = fontProperties.FontWeight == Telerik.Documents.Core.Fonts.FontWeights.Bold;
75+
string fontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
76+
if (fontFamilyName == "Arial" && isBold)
77+
{
78+
using (FileStream fileStream = File.OpenRead(fontFolder + "\\arialbd.ttf"))
79+
{
80+
using (MemoryStream memoryStream = new MemoryStream())
81+
{
82+
fileStream.CopyTo(memoryStream);
83+
return memoryStream.ToArray();
84+
}
85+
}
86+
}
87+
else if (fontFamilyName == "Arial")
88+
{
89+
return this.GetFontDataFromFontFolder("arial.ttf");
90+
}
91+
else if (fontFamilyName == "Calibri" && isBold)
92+
{
93+
return this.GetFontDataFromFontFolder("calibrib.ttf");
94+
}
95+
else if (fontFamilyName == "Calibri")
96+
{
97+
return this.GetFontDataFromFontFolder("calibri.ttf");
98+
}
99+
else if (fontFamilyName == "Segoe UI")
100+
{
101+
return this.GetFontDataFromFontFolder("segoeui.ttf");
102+
}
103+
104+
return null;
105+
}
106+
107+
private byte[] GetFontDataFromFontFolder(string fontFileName)
108+
{
109+
using (FileStream fileStream = File.OpenRead(this.fontFolder + "\\" + fontFileName))
110+
{
111+
using (MemoryStream memoryStream = new MemoryStream())
112+
{
113+
fileStream.CopyTo(memoryStream);
114+
return memoryStream.ToArray();
115+
}
116+
}
117+
}
118+
}
119+
120+
```
121+
122+
## See Also
123+
- [Standard Fonts]({%slug radpdfprocessing-concepts-fonts%})
124+
- [Cross-Platform Support]({%slug radpdfprocessing-cross-platform%})
125+
- [Cross-Platform Support >> Fonts]({%slug radpdfprocessing-cross-platform-fonts%})
126+
- [How to Implement FontsProvider]({%slug pdfprocessing-implement-fontsprovider%})

knowledge-base/pdfprocessing-implement-fontsprovider.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,5 @@ In the validation, each font name (FontFamilyName) must be explicitly specified
118118

119119
## See Also
120120
* [Standard Fonts]({%slug radpdfprocessing-concepts-fonts%})
121-
* [Cross-Platform Support]({%slug radpdfprocessing-cross-platform%})
121+
* [Cross-Platform Support]({%slug radpdfprocessing-cross-platform%})
122+
* [Inserting Special Symbols in PDF using RadPdfProcessing]({%slug inserting-special-symbols-pdf-radpdfprocessing%})

libraries/radpdfprocessing/cross-platform/fonts.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ You can find a detailed **FixedExtensibilityManager** and **FontsProvider** desc
2121
>important If the FontsProvider property is not set, a default font will be used when exporting the document.
2222
2323
## See Also
24-
- [How to Eliminate Formatting Issues when Exporting XLSX to PDF Format]({%slug exporting-xlsx-to-pdf-formatting-issues%})
24+
25+
* [Standard Fonts]({%slug radpdfprocessing-concepts-fonts%})
26+
* [Cross-Platform Support]({%slug radpdfprocessing-cross-platform%})
27+
* [Inserting Special Symbols in PDF using RadPdfProcessing]({%slug inserting-special-symbols-pdf-radpdfprocessing%})
28+
* [How to Eliminate Formatting Issues when Exporting XLSX to PDF Format]({%slug exporting-xlsx-to-pdf-formatting-issues%})
29+

0 commit comments

Comments
 (0)