Thanks guys for your help. I think the confusion was the subtle differences between loading from an assembly vs directly from asp. I have this all worked out now. In my app I was not doing this from a .dll, so that is the major difference between my code (pure asp.net) and other things that have been posted.
For the benefit of others looking at this in the future. If you are doing private fonts from asp.net directly, you need to form your uri like this:
Uri fontUri = new Uri(MappedApplicationPath + "Fonts\\");
In this example you should have a subfolder for your website called "Fonts" that contain all of your font files. Note that I never reference a specific file in my code, you can let PDFsharp do this work for you.
Then add all of your font families (note that you might have 4 files for one family, this doesn't matter, you only call it once per font family):
privateFontCollection.Add(fontUri, "./#FreightDispBlackItalicSC");
privateFontCollection.Add(fontUri, "./#OfficinaSanITCBoo");
Everything else is the same as the demo console project in the pdfsharp wiki.
The key thing about the Uri is that it has to be an absolute path, you cannot use URL format or relative paths. Here is the code for
MappedApplicationPath:
public static string MappedApplicationPath
{
get
{
string APP_PATH = System.Web.HttpContext.Current.Request.ApplicationPath.ToLower();
if (APP_PATH == "/") //a site
APP_PATH = "/";
else if (!APP_PATH.EndsWith(@"/")) //a virtual
APP_PATH += @"/";
string it = System.Web.HttpContext.Current.Server.MapPath(APP_PATH);
if (!it.EndsWith(@"\"))
it += @"\";
return it;
}
}
As was mentioned before, you do NOT need to call System.Windows.Application(); Nor do you need to do anything with packing or resource file properties, etc. like you see in the console app demo from the wiki.