EZFontResolver: a generic font resolver for PDFsharp and MigraDoc

EZFontResolver implements the IFontResolver interface that PDFsharp uses.

In your program, you simply call the AddFont method of EZFontResolver. You simply pass the filename of your font or a byte array containing the font data. Continue reading EZFontResolver: a generic font resolver for PDFsharp and MigraDoc

XTextFormatter revisited: XTextFormatterEx2 for PDFsharp 1.50 beta 2

In an earlier post I described how to improve the XTextFormatter class for PDFsharp 1.32. The problem with that old version: the modified version of XTextFormatter has to be in an assembly with access to the internals of PDFsharp, so you have to compile PDFsharp in order to have an enhanced formatter.

With PDFsharp 1.50 beta things are simpler: all the XTextFormatter class needs is public now and you can use an enhanced version of XTextFormatter even if you are working with the NuGet package of PDFsharp.

My XTextFormatterEx2 has the measuring functionality from XTextFormatterEx. Additionally it allows to control the line spacing. Continue reading XTextFormatter revisited: XTextFormatterEx2 for PDFsharp 1.50 beta 2

Using private fonts with PDFsharp 1.50 beta 2/3 or MigraDoc

Note: The FontResolver interface has changed between PDFsharp 1.50 beta 1 and PDFsharp 1.50 beta 2. This post describes the new solution for PDFsharp 1.50 beta 2 and later versions.

PDFsharp 1.50 implements a new mechanism for private fonts (fonts that are not installed on the system). You simply implement IFontResolver and assign this to a global property:

// That's all it takes to register your own fontresolver
GlobalFontSettings.FontResolver = new DemoFontResolver();

The interesting part is IFontResolver and how you implement it.
Continue reading Using private fonts with PDFsharp 1.50 beta 2/3 or MigraDoc

PDFsharp: Improving the XTextFormatter class: Measuring the height of the text

PDFsharp includes an XTextFormatter class that allows to draw text with line breaks.

A frequently requested feature: how to measure the height of the text before drawing it? I decided to add this measuring functionality. I found it was more difficult than I expected. Continue reading PDFsharp: Improving the XTextFormatter class: Measuring the height of the text

Using private fonts with PDFsharp 1.50 beta or MigraDoc

Note: The FontResolver interface has changed between PDFsharp 1.50 beta 1 and PDFsharp 1.50 beta 2. This post describes the obsolete solution for PDFsharp 1.50 beta 1.
Sample code for PDFsharp 1.50 beta 2.

PDFsharp 1.50 beta 1 implements a new mechanism for private fonts (fonts that are not installed on the system). You simply implement IFontResolver and assign this to a global property:

// That's all it takes to register your own fontresolver
GlobalFontSettings.FontResolver = new DemoFontResolver();

The interesting part is IFontResolver and how you implement it.
Continue reading Using private fonts with PDFsharp 1.50 beta or MigraDoc