PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 8:25 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Feb 03, 2011 12:56 pm 
Offline

Joined: Thu Feb 03, 2011 12:26 pm
Posts: 2
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!


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 04, 2011 6:11 am 
Offline

Joined: Thu Feb 03, 2011 12:26 pm
Posts: 2
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:


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 21, 2011 7:22 pm 
Offline

Joined: Mon Mar 21, 2011 7:17 pm
Posts: 3
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?


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 22, 2011 11:02 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Effenheimer wrote:
Breaks with and without the #

It can't work with #.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 72 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group