Skip to content

Commit 2bda92f

Browse files
Initial commit - Sample added
1 parent 29c3a0f commit 2bda92f

34 files changed

+852
-2
lines changed

README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
1-
# embed-font-in-pdf-csharp
2-
This repository provides C# examples utilizing the Syncfusion PDF library to embed fonts within PDF documents. Learn how to ensure consistent rendering, enhance accessibility, and meet compliance standards. Ideal for .NET developers looking to master font embedding with practical code samples
1+
# Embed Fonts in PDF Documents with C# - A Complete Guide
2+
3+
The Syncfusion .NET PDF Library offers powerful capabilities for embedding fonts in PDF documents, ensuring consistent rendering across devices and platforms. This guide presents a collection of samples that demonstrate how to embed various font types, render complex scripts, optimize file size, and apply font embedding in real-world scenarios.
4+
5+
Sample name | Description
6+
------|------
7+
[Embedding Standard Fonts in PDF](https://github.com/SyncfusionExamples/embed-font-in-pdf-csharp/tree/master/create-pdf-with-standard-font) | Demonstrates how to use built-in standard fonts (like Helvetica, Times New Roman, Courier) in PDF documents. These fonts are widely supported and do not require external font files, making them ideal for basic text rendering.
8+
[Embed a TrueType Font in a PDF Document](https://github.com/SyncfusionExamples/embed-font-in-pdf-csharp/tree/master/embed-truetype-font-in-pdf) | Shows how to embed a TrueType (.ttf) font into a PDF using C#. This ensures that the document retains its intended appearance even if the font is not installed on the viewer’s system.
9+
[Embed OpenType Fonts (OTF) in a PDF Document](https://github.com/SyncfusionExamples/embed-font-in-pdf-csharp/tree/master/embed-otf-font-in-pdf) | Explains how to embed OpenType (.otf) fonts, which support advanced typographic features. This is useful for professional publishing and multilingual documents.
10+
[Rendering Unicode Text in PDF](https://github.com/SyncfusionExamples/embed-font-in-pdf-csharp/tree/master/unicode-multilinqual-text-in-pdf) | Demonstrates how to render Unicode text (e.g., multilingual content) in a PDF by embedding appropriate fonts. This ensures accurate representation of characters from various languages and scripts.
11+
[Rendering Complex Script Text in PDF](https://github.com/SyncfusionExamples/embed-font-in-pdf-csharp/tree/master/complex-script-text-in-pdf) | Shows how to embed fonts that support complex scripts such as Arabic, Hindi, Tamil, or Thai. These scripts require advanced shaping and positioning, which is handled by the embedded font.
12+
[Subsetting Fonts for Optimized File Size](https://github.com/SyncfusionExamples/embed-font-in-pdf-csharp/tree/master/subsetting-fonts-in-pdf) | Illustrates how to subset fonts—embedding only the glyphs used in the document—to reduce the PDF file size while maintaining visual fidelity.
13+
[Embed Fonts in an Existing PDF via PDF/A Conversion](https://github.com/SyncfusionExamples/embed-font-in-pdf-csharp/tree/master/embed-font-in-existing-pdf) | Explains how to embed fonts in an existing PDF document by converting it to PDF/A format, which is designed for long-term archiving and requires all fonts to be embedded.
14+
[Real-World Use Cases](https://github.com/SyncfusionExamples/embed-font-in-pdf-csharp/tree/master/real-world-use-cases) | Highlights practical applications of font embedding:<br>• **Invoice Creator**: Ensures consistent branding and layout across invoices.<br>• **Certificate Generator**: Embeds decorative or signature fonts to maintain design integrity when shared or printed.
15+
16+
## How to run the examples
17+
18+
* Download this project to a location in your disk.
19+
* Open the solution file using Visual Studio.
20+
* Rebuild the solution to install the required NuGet package.
21+
* Run the application.
22+
23+
## Resources
24+
25+
* **Product page:** [Syncfusion PDF Framework](https://www.syncfusion.com/document-processing/pdf-framework/net)
26+
* **Documentation page:** [Syncfusion .NET PDF library](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/overview)
27+
* **Online demo:** [Syncfusion .NET PDF library - Online demos](https://ej2.syncfusion.com/aspnetcore/pdf/default#/fluent2)
28+
* **Blog:** [Syncfusion .NET PDF library - Blog](https://www.syncfusion.com/blogs/category/pdf)
29+
* **Knowledge Base:** [Syncfusion .NET PDF library - Knowledge Base](https://www.syncfusion.com/kb/windowsforms/pdf)
30+
* **EBooks:** [Syncfusion .NET PDF library - EBooks](https://www.syncfusion.com/succinctly-free-ebooks)
31+
* **FAQ:** [Syncfusion .NET PDF library - FAQ](https://www.syncfusion.com/faq/)
32+
33+
## Support and feedback
34+
35+
* For any other queries, reach our [Syncfusion support team](https://www.syncfusion.com/support/directtrac/incidents/newincident?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) or post the queries through the [community forums](https://www.syncfusion.com/forums?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples).
36+
* Request new feature through [Syncfusion feedback portal](https://www.syncfusion.com/feedback?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples).
37+
38+
## License
39+
40+
This is a commercial product and requires a paid license for possession or use. Syncfusion’s licensed software, including this component, is subject to the terms and conditions of [Syncfusion's EULA](https://www.syncfusion.com/eula/es/?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples). You can purchase a licnense [here](https://www.syncfusion.com/sales/products?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) or start a free 30-day trial [here](https://www.syncfusion.com/account/manage-trials/start-trials?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples).
41+
42+
## About Syncfusion
43+
44+
Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion has more than 26,000+ customers and more than 1 million users, including large financial institutions, Fortune 500 companies, and global IT consultancies.
45+
46+
Today, we provide 1600+ components and frameworks for web ([Blazor](https://www.syncfusion.com/blazor-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [ASP.NET Core](https://www.syncfusion.com/aspnet-core-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [ASP.NET MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [ASP.NET WebForms](https://www.syncfusion.com/jquery/aspnet-webforms-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [JavaScript](https://www.syncfusion.com/javascript-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Angular](https://www.syncfusion.com/angular-ui-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [React](https://www.syncfusion.com/react-ui-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Vue](https://www.syncfusion.com/vue-ui-components?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), and [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples)), mobile ([Xamarin](https://www.syncfusion.com/xamarin-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [UWP](https://www.syncfusion.com/uwp-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), and [JavaScript](https://www.syncfusion.com/javascript-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples)), and desktop development ([WinForms](https://www.syncfusion.com/winforms-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [WPF](https://www.syncfusion.com/wpf-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [WinUI(Preview)](https://www.syncfusion.com/winui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples), [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples) and [UWP](https://www.syncfusion.com/uwp-ui-controls?utm_source=github&utm_medium=listing&utm_campaign=github-docio-examples)). We provide ready-to-deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software.
47+
48+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Syncfusion.Drawing;
2+
using Syncfusion.Pdf;
3+
using Syncfusion.Pdf.Graphics;
4+
5+
//Create a new PDF document
6+
using (PdfDocument document = new PdfDocument())
7+
{
8+
//Add a page to the document
9+
PdfPage page = document.Pages.Add();
10+
11+
//Create string format and enable complex script support
12+
PdfStringFormat format = new PdfStringFormat() { ComplexScript = true };
13+
14+
//Load a TrueType font for Thai language
15+
PdfTrueTypeFont thaiUnicodeFont = new PdfTrueTypeFont(new FileStream("../../../../data/tahoma.ttf", FileMode.Open), 14);
16+
17+
//Draw the Thai text
18+
page.Graphics.DrawString("สวัสดีชาวโลก", thaiUnicodeFont, PdfBrushes.Black, new RectangleF(0, 130, 300, 50), format);
19+
20+
//Create Unicode font for Indic language
21+
PdfTrueTypeFont indicUnicodeFont = new PdfTrueTypeFont(new FileStream("../../../../data/NotoSansTamil-Regular.ttf", FileMode.Open), 14);
22+
23+
//Draw the Indic text
24+
page.Graphics.DrawString("வணக்கம் உலகம்", indicUnicodeFont, PdfBrushes.Black, new RectangleF(0, 180, 300, 50), format);
25+
26+
//Load a Unicode font for Arabic language
27+
PdfTrueTypeFont arabicUnicodeFont = new PdfTrueTypeFont(new FileStream("../../../../data/arial.ttf", FileMode.Open), 14);
28+
29+
//Set the text direction for right to left languages
30+
format.TextDirection = PdfTextDirection.RightToLeft;
31+
32+
page.Graphics.DrawString("مرحبا بالعالم", arabicUnicodeFont, PdfBrushes.Black, new RectangleF(0, 230, 300, 50), format);
33+
34+
//Save the document
35+
document.Save("complex-script-text-in-pdf.pdf");
36+
}
37+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>complex_script_text_in_pdf</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36310.24 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "complex-script-text-in-pdf", "complex-script-text-in-pdf.csproj", "{803E16D2-04A2-41D0-B115-A9797A04737F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{803E16D2-04A2-41D0-B115-A9797A04737F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{803E16D2-04A2-41D0-B115-A9797A04737F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{803E16D2-04A2-41D0-B115-A9797A04737F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{803E16D2-04A2-41D0-B115-A9797A04737F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {F4AA9EDE-625E-4A02-8BE3-1314EAEF6834}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Syncfusion.Drawing;
2+
using Syncfusion.Pdf;
3+
using Syncfusion.Pdf.Graphics;
4+
5+
//Create a new PDF document
6+
using (PdfDocument document = new PdfDocument())
7+
{
8+
//Add a page to the document
9+
PdfPage page = document.Pages.Add();
10+
//Create a font
11+
PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
12+
//Draw text on the page
13+
page.Graphics.DrawString("Hello, PDF with Standard Font!", font, PdfBrushes.Black, new PointF(10, 10));
14+
//Save the document
15+
document.Save("embed-standard-font.pdf");
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>create_pdf_with_standard_font</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36310.24 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "create-pdf-with-standard-font", "create-pdf-with-standard-font.csproj", "{4D7347FC-7A5E-4EEF-96E0-E210924E7180}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{4D7347FC-7A5E-4EEF-96E0-E210924E7180}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{4D7347FC-7A5E-4EEF-96E0-E210924E7180}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{4D7347FC-7A5E-4EEF-96E0-E210924E7180}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{4D7347FC-7A5E-4EEF-96E0-E210924E7180}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {2F631603-99F2-4E0E-82A7-0AA510F99472}
24+
EndGlobalSection
25+
EndGlobal

data/BRUSHSCI.TTF

52.2 KB
Binary file not shown.

data/NotoSansTamil-Regular.ttf

77.1 KB
Binary file not shown.

data/NotoSerif-Black.otf

286 KB
Binary file not shown.

0 commit comments

Comments
 (0)