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

41 views
Skip to first unread message

Ryan

unread,
Sep 19, 2014, 2:44:23 PM9/19/14
to pdfne...@googlegroups.com
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());


Reply all
Reply to author
Forward
0 new messages