Persits Software, Inc. Knowledge Base Articles

Wider than normal word and/or character spacing when using DrawText

Problem Description

When using AspPDF or AspPDF.NET to draw on an existing PDF document via the method DrawText the output text sometimes appears with wider than normal gaps between words and/or characters.

In the text "John Q Public", word spacing is wider than normal, while in the text "Company Name" character spacing is wider than normal.


The problem is caused by the existing page content which changes the current character and/or word spacing parameters and affects new text as well. To set the current character spacing back to default (0), the following code should be used before calling DrawText:

objPage.Canvas.Append("0 Tc ");

To set the current word spacing back to 0, use the code

objPage.Canvas.Append("0 Tw ");

The two lines can be combined into one, if necessary:

objPage.Canvas.Append("0 Tw 0 Tc ");

Note that the commands Tc and Tw must always be followed by a space.