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

Embedding Font in MigraDoc
http://forum.pdfsharp.de/viewtopic.php?f=2&t=1322
Page 1 of 1

Author:  Zoidberg [ Fri Sep 03, 2010 6:50 pm ]
Post subject:  Embedding Font in MigraDoc

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

Author:  () => true [ Sat Sep 04, 2010 6:08 pm ]
Post subject:  Re: Embedding Font in MigraDoc

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.

Author:  Zoidberg [ Mon Sep 06, 2010 8:52 am ]
Post subject:  Re: Embedding Font in MigraDoc

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

Author:  Zoidberg [ Fri Sep 17, 2010 9:03 am ]
Post subject:  Re: Embedding Font in MigraDoc

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

Author:  Thomas Hoevel [ Mon Sep 20, 2010 7:45 am ]
Post subject:  Re: Embedding Font in MigraDoc

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 6281 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.

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