Use basic PDF objects for currently unsupported PDF features in C# and VB.NET

Private fonts are fonts that are not installed or don’t need to be installed on the computer that executes your PDF app. The use of private fonts is required in restricted environments, such as ASP.NET applications running at medium reliability. Private fonts can be embedded in assemblies or placed in custom directories.

PDF .Net allows you to use either system or private fonts when writing text. The PdfFonts class allows you to browse all standard, system, and private font families and font faces.

Note that PDF .Net ignores the font embedding rights. Therefore, it is the responsibility of the application developer to perform a font license rights check. If in doubt, contact the font vendor.

The image below shows the result of the example code snippet we used to demonstrate how to write text using private fonts (Almonte Snow.ttf and almonte woodgrain.ttf). Note that these are in the same directory as the application.

Complete code

using System;
using SautinSoft.Pdf;
using System.IO;

class Program
{
	static void Main()
	{
		// This property is necessary only for licensed version.
		//SautinSoft.Pdf.Serial = "XXXXXXXXXXX";

		using (var document = new PdfDocument())
		{
			var page = document.Pages.Add();

			using (var formattedText = new PdfFormattedText())
			{
				formattedText.FontSize = 48;
				formattedText.LineHeight = 72;

				// Use the font family 'Almonte Snow' whose font file is located in the same directory as the application.
				formattedText.FontFamily = new PdfFontFamily(null, "Almonte Snow");
				formattedText.AppendLine("SautinSoft HELLO 1!");

				// Use the font family 'Almonte Woodgrain' whose font file is located in the same directory as the application.
				formattedText.FontFamily = new PdfFontFamily(null, "Almonte Woodgrain");
				formattedText.AppendLine("SautinSoft HELLO 2!");

				// Another way to use the font family 'Almonte Snow' whose font file is located in the same directory as the application.
				formattedText.FontFamily = PdfFonts.GetFontFamilies(null).First(ff => ff.Name == "Almonte Snow");
				formattedText.AppendLine("SautinSoft HELLO 3!");

				// Another way to use the font family 'Almonte Woodgrain' whose font file is located in the same directory as the application.
				formattedText.FontFamily = PdfFonts.GetFontFamilies(null).First(ff => ff.Name == "Almonte Woodgrain");
				formattedText.Append("SautinSoft HELLO 4!");

				page.Content.DrawText(formattedText, new PdfPoint(100, 500));
			}

			document.Save("Private Fonts.pdf");

		}
	}
}

            

Download.


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.