Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top