Unable to retrieve the character width of "Smart Quotes" when using standard Type1 / built-in fonts and pdftron.PDF.Font.GetWidth

Product: PDFNet Dynamic Link Library for .NET 4.5.1 and above

Product Version: 11.12.8.6892

Please give a brief summary of your issue: pdftron.PDF.Font.GetWidth() returns 0 for some characters.

Please describe your issue and provide steps to reproduce it: We are trying to use the pdftron.PDF.Font.GetWidth() method to determine the character width / advance on certain characters. When we use it using the “built-in” fonts, some characters (like the smart quote characters such as Unicode 8220 “Left Double Quotation Mark: “) we get back 0 (instead of a valid width).

We tried marking the font as “embedded” as well, and get the same result.

Please provide a link to a minimal sample where the issue is reproducible:

pdftron.PDFNet.Initialize(LICENSE_KEY);
pdftron.PDF.PDFDoc doc = new pdftron.PDF.PDFDoc();
pdftron.PDF.Font font = pdftron.PDF.Font.Create(doc, type: pdftron.PDF.Font.StandardType1Font.e_helvetica);
foreach (char c in new char [] { 'A', '“', '§' })
{
  double width = font.GetWidth(char_code: (int)c);
  System.Console.WriteLine($"font.GetWidth('{c}') = {width}");
}

Produces:
PDFNet is running in demo mode.
PackageV2: base
font.GetWidth(‘A’) = 667
font.GetWidth(‘"’) = 0
font.GetWidth(‘’) = 556

Hello Michael,

This is expected because the Unicode 8220 is out of range of the character set included in the built-in type 1 font for Helvetica and the glyph for that character is not included. The list of characters is similar to the Extended Ascii character set.

If you must use the built in font, you can find the full list of characters within the PDF 2.0 Spec which Apryse, Adobe, and Foxit have sponsored to be free to the public. The full list of glyphs/characters are found within Annex D.

With that being said, we generally recommend letting the system pull the font from the OS by modifying the Create method similar to below:

pdftron.PDF.Font.Create(doc, "helvetica", "A“§");

This will use our SDK to match a font that contains the characters in the final string.

Let us know if you have any additional questions.