PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 18, 2024 1:20 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Sep 03, 2010 6:50 pm 
Offline

Joined: Fri Sep 03, 2010 6:18 pm
Posts: 5
Location: Munich (Germany)
Hello together,

I am new in this Forum and I want to thank everbody in advance for helping me.
I thougt it wouldn't be a big thing to embed a truetype font but obviously for me it is.
The facts: I try to embed a tt-font which is located at the highest level of my project into a pdf document with vb.net (framework 4) and MigraDoc 1.31. I read much on how to do that so in my opinion it should work like this:
-------------------------------
Imports PdfSharp.Drawing

Dim FontCollection = New PdfSharp.Drawing.XPrivateFontCollection
FontCollection.Add(New Uri(BaseURI), "./#FamilyName")
Dim xFont = New XFont("FamilyName", 11)
-------------------------------
When I run the program I get always "Cannot get a matching glyph typeface for font 'FamilyName'."
- For FamiliyName I tried the FontName and FontFileName.
- For BaseURI I tried a path like file:///c:/ and pack://application:,,,/AssemblyName;component/. I tried both BaseURI also with FontFileName at the end.
- I tried to use SystemFonts like Tahoma, what certainly worked.
- I tried around with artificial FamilyNames like "qkjhdflkqfh", what didn't make any difference

I am wondering that according to the examples, it should work without ever mention the FontFileName. Is that right? And what about this FamilyName? I know what it is but I never created one and assigned my font or something like this. Could some please explain me that, because I already spent hours fixing that.

Thanks
Timo


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 04, 2010 6:08 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 343
Hi!

Several things can go wrong.

Change the compile tool you call for the font.
Depending on the compile tool, the font will end up at different places in the assembly ...
Look at the sample for the correct tool setting.

The URI strings can be a pain.
Do it like we did in the sample.

IIRC the FamilyName is simply the name you use in your MigraDoc document to refer to the font.

You can begin with the font from the sample code - just in case your font files in a format that is not supported.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 06, 2010 8:52 am 
Offline

Joined: Fri Sep 03, 2010 6:18 pm
Posts: 5
Location: Munich (Germany)
Thank you for replying. The path shouldn't be the problem because in the meantime I tried to embed the font in several other ways:

In XAML I used the following code to format a Textblock and it worked
<TextBlock FontFamily="/AssemblyName;Component/fonts/#FontName" Text="Blabla" />

In VB I used the following code to format another Textblock and it worked
TextBlockName.FontFamily = New System.Windows.Media.FontFamily(New Uri("pack://application:,,,/AssemblyName;component/"), "./fonts/#FontName")

Could you please explain what you meant with "Change the compile tool you call for the font"? Do have another advice?

Thanks
Timo


Top
 Profile  
Reply with quote  
PostPosted: Fri Sep 17, 2010 9:03 am 
Offline

Joined: Fri Sep 03, 2010 6:18 pm
Posts: 5
Location: Munich (Germany)
I'm one step further. My font now works when it is installed as a system font. My uri is also right, I checked it with
Code:
For Each fontFamily As System.Windows.Media.FontFamily In Fonts.GetFontFamilies(New Uri("pack://application:,,,/MyAssemblyName;Component/fonts/"))
     MsgBox(fontFamily.ToString)
Next fontFamily

What did you mean with "Change the compile tool for the font"?
Do I have to tell the PdfDocumentRenderer where to look for the font? I mean, does it also look in my PrivateFontCollection on its own?
I am a little bit confused by the different classes. In my code I use a MigraDoc.DocumentObjectModel.Font for the renderer. Is that right? When I read about this subject here in the forum everyone uses the PdfSharp.Drawing namespace but this not for WPF, right?

Thanks.
Timo


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2010 7:45 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Zoidberg wrote:
Could you please explain what you meant with "Change the compile tool you call for the font"?

What was meant is actually called "Build Action" in the properties:
Attachment:
PDFsharp Private Fonts.png
PDFsharp Private Fonts.png [ 10.65 KiB | Viewed 6279 times ]


It took hours to get the sample running - and now we always do it as we did with the sample.
We don't know if this is the best way - but it's a way that works.

With PDFsharp/MigraDoc 1.31 you must use the WPF build to use private fonts.

Some people use PDFsharp for low-level PDF file operations, some use MigraDoc for high-level document generation.
MigraDoc uses PDFsharp internally.
Both MigraDoc and PDFsharp exist as GDI+ and WPF builds.
"PdfSharp.Drawing" is a PDFsharp namespace.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 15 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