How do I load a font using just the font name/family?

Q:

We would like to avoid using absolute paths to fonts when calling Font::CreateCIDTrueTypeFont. Is it possible to load a font based just on the font name or family?

A:

Simply call Font.Create(pdfDoc, @“fontname”); and it will find the the closest matching font in the OS. Note you will need to use ElementBuilder.CreateUnicodeTextRun with these fonts.

For example on Windows the following should load the ComicSans font.

element = eb.CreateTextBegin(Font::Create(*doc.GetSDFDoc(), “comic sans”)`, 12);
writer.WriteElement(element);
element = eb.CreateUnicodeTextRun(“Hello World”);
element->SetTextMatrix(1, 0, 0, 1, 50, 400);
writer.WriteElement(element);
writer.WriteElement(eb.CreateTextEnd());

`