PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 4:32 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Nov 06, 2011 4:40 pm 
Offline

Joined: Sun Nov 06, 2011 4:21 pm
Posts: 3
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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 07, 2011 3:39 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Hi!

PDFsharp includes a PrivateFonts sample that shows the trick.

Code:
XPrivateFontCollection globalFontCollection = XPrivateFontCollection.Global;


Add your fonts to this collection.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 10, 2011 9:54 pm 
Offline

Joined: Sun Nov 06, 2011 4:21 pm
Posts: 3
It worked! Thanks for the help.


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

All times are UTC


Who is online

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