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.