PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

Need some help with embedding a font
http://forum.pdfsharp.de/viewtopic.php?f=2&t=1527
Page 1 of 1

Author:  WernerVa [ Thu Feb 03, 2011 12:56 pm ]
Post subject:  Need some help with embedding a font

Hi everyone.

First off I'd like to say that I know there are exaples and samples available but I've tried them and even though the compiled samples from the source-forge download work I can't get the same results in my own app.

I am using PdfSharp and MigraDoc 1.31. At first I used the GDI+ versions but I switched to the WPF version.

Some background on my app. My app is a website (.Net MVC 2). I wish to serve dynamically created pdf documents (invoices) to users as part of the functionality. The code that generates the pdf documents is a C# class library which references the PdfSharp and MigraDoc dll's.

So far I've been able to successfull create the documents complete with headers and footers and page count indicators using MigraDoc 1.31. I use MigraDoc to generate the documents and then render it to pdf.

The next step is to use a specific font for some of the text. As far as I can tell I can do this by embedding the font. This is where I strike out though.

My app is not wpf. It's MVC.

I have copied the code from the Private Fonts sample:

Code:
// Without the following line of code the Uri constructor (see below) fails...
      new System.Windows.Application();

      // Add the 3 type faces of 'FrutigerLight' from the resources
      Uri uri = new Uri("pack://application:,,,/");
      //const string name = "./FrutigerFonts/#FrutigerLight";
      //const string name = "./Fonts/#Early Tickertape";
      const string name = "./#Early Tickertape";
      globalFontCollection.Add(uri, name);

      // Add 2 type faces of 'Frutiger' from the resources
      //globalFontCollection.Add(uri, "./FrutigerFonts/#Frutiger");
      //globalFontCollection.Add(uri, "./Fonts/#Oblivious font");
      globalFontCollection.Add(uri, "./#Oblivious font");


Running the sample works fine, but in my app an exception s thrown stating Invalid URI: A port was expected because of there is a colon (':') present but the port could not be parsed.

My code looks like this:

Code:
private void EmbedFont()
        {
            Uri uri = new Uri("pack://application:,,,/");
            XPrivateFontCollection globalFontCollection = XPrivateFontCollection.Global;
            globalFontCollection.Add(uri, "./#Avenir LT Std 65 Medium");           
        }


I've been trying to figure this out for a solid day now and all I've got so far is tired and frustrated. Please help!

Author:  WernerVa [ Fri Feb 04, 2011 6:11 am ]
Post subject:  Re: Need some help with embedding a font

It's amazing what some sleep does.

I had another look at the sample code code this morning and noticed that I had missed something:

Code:
// Without the following line of code the Uri constructor (see below) fails...
new System.Windows.Application();


It even had a comment about it being important which, somehow, I missed. Awesome :roll:

So I put that part in there and hey presto!

Well not exactly. The embedding works (I think) but now I get a new error "Cannot get a matching glyph typeface for font 'Avenir LT Std 65 Medium'."

Who's what? I'll see what I can google. Feel free to help :wink:

Author:  Effenheimer [ Mon Mar 21, 2011 7:22 pm ]
Post subject:  Re: Need some help with embedding a font

Was this ever resolved?

I am attempting to use the WPF version of PDFsharp and MigraDoc with an ASP.NET website. It works until I want to embed a font. I cannot use my font because I keep getting the "Cannot get a matching glyph typeface for font" error.

Some code I'm using:

XPrivateFontCollection privateFontCollection = new XPrivateFontCollection();
Uri fontUri = new Uri(baseUrl + "/public/fonts/FreightDispBlackItalicSC.ttf");
privateFontCollection.Add(fontUri, "./#FreightDispBlackItalicSC");

DocumentRenderer documentRenderer = new DocumentRenderer(doc);
documentRenderer.PrivateFonts = privateFontCollection;
...

When I'm actually setting the paragraph font I use the following code..
paragraph.Format.Font.Name = "#FreightDispBlackItalicSC"; // Breaks with and without the #

Any help/thoughts?

Author:  Thomas Hoevel [ Tue Mar 22, 2011 11:02 am ]
Post subject:  Re: Need some help with embedding a font

Effenheimer wrote:
Breaks with and without the #

It can't work with #.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/