Examples

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


  1. Create a Document object.
  2. Create a Page object.
  3. Create a TextArea object and add the text to be displayed.
  4. Enable kerning for the text area by setting the KerningEnabled property to true .
  5. Loop over the TextArea instance's KernValues 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.
  6. Add the Document object's Draw 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.


Clone or View Example Project on GitHub

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.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

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

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.


Why Choose DynamicPDF?

  • Transparent Pricing
  • Lots of Features
  • Easy to Use
  • Great Support
  • Efficient Performance
  • Product Maturity (Over 22 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

We’re Not The Only Ones That Think We’re Great!