facebooktwittermenuarrow-up

GemBox Support Forum

Private font dont work

Hello, I have a problem with a specific private font when I generate pdf, the 5 MT GBS Code 2 font does not work, this font shows code bars.

I’ve made a simple project to debug this problem, but I can’t get it to work with all the suggestions posted.

the FontSettings.Fonts IList class shows the font installed in the project, but it doesn’t work internally when saving PDF, the text doesn’t show the bar code. Does not generate any exception

This is the code I am using:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using GemBox.Document;

namespace PruebaPDFCodebar
{
    class Program
    {
        static void Main(string[] args)
        {
            ComponentInfo.SetLicense("FREE-LIMITED-KEY");
            FontSettings.FontsBaseResourceLocation = "/Resources/";
            IList<FontFile> P = FontSettings.Fonts;
            int chk = 0;
            foreach (FontFile font in P)
            {
                if (font.FamilyName == "GBS Code 2 of 5 MT")
                {
                    chk = 1;
                }
            }
            if (chk == 1)
            {
                DocumentModel aDoc;
                aDoc = new DocumentModel();
                aDoc.Sections.Add(new Section(aDoc, new Paragraph(aDoc, new Run(aDoc, "’’“Éé˜")
                {
                    CharacterFormat = { FontName = "GBS Code 2 of 5 MT" }
                },
                new SpecialCharacter(aDoc, SpecialCharacterType.LineBreak))));
                aDoc.Save("C:\\PRUEBACODEBAR\\PRUEBACODEBAR.DOCX");
                aDoc = DocumentModel.Load("C:\\PRUEBACODEBAR\\PRUEBACODEBAR.DOCX");
                aDoc.Save("C:\\PRUEBACODEBAR\\PRUEBACODEBAR.PDF");
            }
            else
            {
                MessageBox.Show("ERROR EN FUENTE GBS CODE 2 OF 5 MT");
            }
        }
    }
}

image with font resource configured like “Resource”
when I see the .docx document with local installed font shows it well
when I see the pdf document gembox dont used the correct font.

I need support to fix it.

Hi Facundo,

Can you please send us that “GBS Code 2 of 5 MT” font file so that we can reproduce this issue and investigate it?

Regards,
Mario

Yes of course, pls download it

Hello Mario, were you able to reproduce the issue with the font?

Hi Facu!

We investigated the issue and the problem is that font “GBS Code 2 of 5 MT” is a non-Unicode (symbolic) font and MS Word maps characters \u2019 (first and second char in your test string), \u201c (third char in your test string), and \u02dc (last char in your test string) to glyph indices 106, 107, and 112 in an unknown way that is not according to OpenType / TrueType font standard.

GemBox.Document doesn’t perform font fallback for symbolic fonts because the semantic meaning of each char/glyph pair in a symbolic font is meaningful for that font only. This is why all characters are simply rendered with a default fallback font (Segoe UI) in the output PDF file.

As stated in the OpenType / TrueType font standard, you should instead use Unicode Private-Use Area (PUA) characters supported by “GBS Code 2 of 5 MT” font.

The following code shows how to retrieve PUA characters supported by “GBS Code 2 of 5 MT” font by using the WPF’s GlyphTypeface class. The code also shows how to convert your test string to PUA characters and lists all PUA characters and associated glyphs supported by the “GBS Code 2 of 5 MT” font in a table so that you can map each output bar-code glyph to the appropriate input PUA character.

var desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

var glyphTypeface = new System.Windows.Media.GlyphTypeface(new Uri(Path.Combine(desktop, "GBS Code 2o5 MT.ttf")));

var supportedPuaChars = new string(glyphTypeface.CharacterToGlyphMap.Keys.Where(c => (c & 0xF000) == 0xF000).OrderBy(c => c).Select(c => Convert.ToChar(c)).ToArray());

var document = new DocumentModel();

var section = new Section(document) { PageSetup = { TextColumns = new TextColumnCollection(3) } };
document.Sections.Add(section);

section.Blocks.Add(new Paragraph(document,
    new Run(document, "Old value: "),
    new Run(document, "’’“Éé˜") { CharacterFormat = { FontName = "GBS Code 2 of 5 MT" } }));

section.Blocks.Add(new Paragraph(document,
    new Run(document, "New value: "),
    new Run(document, "\uf092\uf092\uf093\uf0c9\uf0e9\uf098") { CharacterFormat = { FontName = "GBS Code 2 of 5 MT" } }));

var table = new Table(document);
table.Rows.Add(new TableRow(document,
    new TableCell(document, new Paragraph(document, new Run(document, "Character") { CharacterFormat = { Bold = true } })),
    new TableCell(document, new Paragraph(document, new Run(document, "Glyph") { CharacterFormat = { Bold = true } }))));
for (int i = 0; i < supportedPuaChars.Length; ++i)
{
    table.Rows.Add(new TableRow(document,
        new TableCell(document, new Paragraph(document, new Run(document, "\"\\u" + Convert.ToString((int)supportedPuaChars[i], 16) + "\""))),
        new TableCell(document, new Paragraph(document, new Run(document, supportedPuaChars[i].ToString()) { CharacterFormat = { FontName = "GBS Code 2 of 5 MT" } }))));
}
section.Blocks.Add(table);

document.Save(Path.Combine(desktop, "GBS Code 2o5 MT.docx"));
document.Save(Path.Combine(desktop, "GBS Code 2o5 MT.pdf"));

Regards,
Stipo

I greatly appreciate the support, I will try considering what is indicated using the supplied code to adjust my program. Thank you very much, greetings.