PDFsharp & MigraDoc Forum
https://forum.pdfsharp.net/

PrivateFontCollection with both PDFSharp and Migradoc
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1835
Page 1 of 1

Author:  Derek [ Sun Nov 06, 2011 4:40 pm ]
Post subject:  PrivateFontCollection with both PDFSharp and Migradoc

First off, let me thank the developers for this fine code. I've been making PDFs with it for a while and it's great.

My problem is I cannot get the privatefontcollection to work. I have a rather long webapp that combines Migradoc forms into a PDFSharp PDF, so my private fonts must work with both. (I saw the other post about having to pass the collection to the renderer.)

I'm at a loss as how to bind the Xprivatefontcollection to the PDFSharp PDF. I see how to do this in Migradoc, but how do I do this with PDFSharp? I noticed through Object Browser that PdfSharp.Pdf.PdfDocumentSettings has a PrivateFontCollection, but I cannot access it.

My exact error is "Cannot get a matching glyph typeface for font 'Lucida Calligraphy'."

Here's a bit of code:
Code:
    Public Function GetPrivateFontCollection() As XPrivateFontCollection
        Dim FC As New XPrivateFontCollection
        Dim URI As System.Uri
        URI = New Uri("file:///" + HttpContext.Current.Request.MapPath("~/Fonts/"))
        FC.Add(URI, "./#Calibri")
        FC.Add(URI, "./#Book Antiqua")
        FC.Add(URI, "./#Lucida Calligraphy")
        Return FC
    End Function


The error shows up when I try to access the font. I'm positive that the privatefontcollection is out of scope of the code, but I cant figure out how to bring it in. (I've trimed much of the code to simplify the sample)

Code:
Dim MyPDF As PdfSharp.Pdf.PdfDocument
Dim MyPage As Pdf.PdfPage
Dim GFX As XGraphics
Dim MyFont As XFont
Dim MyFontCollection As XPrivateFontCollection = GetPrivateFontCollection()
Dim TF As XTextFormatter

MyPDF = New PdfSharp.Pdf.PdfDocument
MyPage = MyPDF.AddPage
GFX = XGraphics.FromPdfPage(MyPage)
GFX.MFEH = PdfFontEmbedding.Always
TF = New XTextFormatter(GFX)
Dim Options As New XPdfFontOptions(PdfFontEncoding.WinAnsi, PdfFontEmbedding.Automatic)
MyFont = New XFont(MyCard.Font1, 1, XFontStyle.Regular, Options)  <-- Error here


Can anybody give me a hand? As usual, It's a desperate situation and I'd love to get this over with.

Author:  Thomas Hoevel [ Mon Nov 07, 2011 3:39 pm ]
Post subject:  Re: PrivateFontCollection with both PDFSharp and Migradoc

Hi!

PDFsharp includes a PrivateFonts sample that shows the trick.

Code:
XPrivateFontCollection globalFontCollection = XPrivateFontCollection.Global;


Add your fonts to this collection.

Author:  Derek [ Thu Nov 10, 2011 9:54 pm ]
Post subject:  Re: PrivateFontCollection with both PDFSharp and Migradoc

It worked! Thanks for the help.

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