Вопрос

was wondering why I can't cast the System.Drawing.Font to MigraDoc.DocumentObjectModel.Font. I need to load a specific font in my application. I want to do it through Styles like this:

PrivateFontCollection pfc;
FontFamily family = LoadFontFamily(@".\fonts\TitilliumWeb\TitilliumWeb-Black.ttf", out pfc);
System.Drawing.Font titilliumWeb = new System.Drawing.Font(family, 11.0f);

style.Font.ApplyFont((MigraDoc.DocumentObjectModel.Font) titilliumWeb);

Or even better can I easily create a MigraDoc Font somehow?

Found a link on how to add fonts to MigraDoc, but it didn't really helped me http://www.pdfsharp.net/wiki/PrivateFonts-sample.ashx

Это было полезно?

Решение

Casting works only if one class was derived from the other or implements an interface.

The technique shown in the Private Fonts sample works (currently it works with the WPF build only, so if you use the GDI+ build of PDFsharp/MigraDoc, just switch to the WFP build).

You register the fonts you need in the PrivateFontCollection. You just give the Font name in the style definitions and MigraDoc will use the fonts to create PDF files.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top