将System.Drawing.Font转换为MigraDoc.DocumentObjectModel.Font?

时间:2013-06-09 22:16:24

标签: fonts casting system.drawing migradoc

想知道为什么我不能将System.Drawing.Font强制转换为MigraDoc.DocumentObjectModel.Font。 我需要在我的应用程序中加载特定的字体。我想通过这样的样式来做到这一点:

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);

或者甚至可以更好地以某种方式轻松创建MigraDoc字体?

找到了一个关于如何向MigraDoc添加字体的链接,但它并没有真正帮助我 http://www.pdfsharp.net/wiki/PrivateFonts-sample.ashx

1 个答案:

答案 0 :(得分:0)

仅当一个类派生自另一个类或实现接口时,才能进行转换。

私有字体示例中显示的技术有效(目前它仅适用于WPF构建,因此如果您使用GDI +构建的PDFsharp / MigraDoc,只需切换到WFP构建)。

您在PrivateFontCollection中注册所需的字体。您只需在样式定义中指定字体名称,MigraDoc将使用字体创建PDF文件。