Add Font Kerning and Tracking to PDFs
Adjusting the spacing between letter pairs (kerning) or between all characters (tracking) is a breeze when using DynamicPDF Core Suite for .NET. The following C# example shows you how.
How to Use Font Kerning and Tracking
The following steps and C# sample code illustrate using font kerning and tracking in a PDF document using DynamicPDF Core Suite for .NET.
Steps for Using Fonts in a PDF Document
- Create a
Document
object. - Create a
Page
object. - Create a
TextArea
object and add the text to be displayed. - Enable kerning for the text area by setting the
KerningEnabled
property totrue
. - Loop over the
TextArea
instance'sKernValues
spacing array and assign a value for every pair (or pair subset). Assign a positive value to reduce the space between characters or assign a negative value to increase the space between characters. - Add the
Document
object'sDraw
method to draw and save the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
string text = "To and WA are examples of when kerning would be used.";
TextArea textArea = new TextArea(text, 10, 10, 400, 700, Font.TimesRoman);
textArea.KerningEnabled = true;
KerningValues kernValues = textArea.GetKerningValues();
for (int i = 0; i < kernValues.Spacing.Length; i++)
{
kernValues.Spacing[i] = (short)(kernValues.Spacing[i] - 400);
}
page.Elements.Add(textArea);
document.Pages.Add(page);
document.Draw("output.pdf");
GitHub Project
Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This example code is contained in the following files.
- C# - FontKerning.cs
- VB.NET - FontKerning.vb
Getting Started
Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing.
NuGet Package
The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.
DynamicPDF Core Suite Information
DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!
More Information on Font Kerning and Tracking
- Refer to the Fonts and Text documentation topic, or
- Chapter 8, Fonts and Colors, in the book DynamicPDF Core Suite for .NET by Example available on GitHub.
Available on Other Platforms
DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- DynamicPDF Generator
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX
- DynamicPDF Merger
- Java - DynamicPDF Merger for Java
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX