Hello!
I'm new to PDFSharp and MigraDoc (Just started a few days ago) and I'm having a hell of a time trying to figure out how to use private fonts with MigraDoc. I have scoured this forum and Google for the last day and cannot seem to piece together a solution for this conundrum.
Problem:I have a Windows Forms Application written in vb.net that I am deploying via ClickOnce. This form allow the end user to print reports to PDF (via MigraDoc) that contain a barcode font called “Free 3 of 9 Extended” (The font file is included in the Application.StartupPath and is named “FRE3OF9X.TTF”) . Unfortunately ClickOnce cannot install fonts as part of its deployment process so I am looking at using the private font collection.
I have already looked at the following resources and can't figure out how to make these suggestions work within the MigraDoc objects:
viewtopic.php?f=2&t=1880http://www.pdfsharp.net/wiki/PrivateFonts-sample.ashxInfoMigraDocs - WPF - Version 1.32
Objective:My objective is to use the barcode font without installing it to the pc via a private font collection. Then have that font recognized within MigraDoc.
For example: Paragraph.Format.Font.Name = "Free 3 of 9 Extended"
For the purposes of this thread I created a simple form that contains only a button called Button1. Any idea how I can get this to work?
Code:
Imports MigraDoc.DocumentObjectModel
Imports MigraDoc.DocumentObjectModel.Tables
Imports MigraDoc.Rendering
Imports PdfSharp.Pdf
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Creates the document object
Dim document As New Document()
document.DefaultPageSetup.PageFormat = PageFormat.A4
document.DefaultPageSetup.PageHeight = "11in"
document.DefaultPageSetup.PageWidth = "8.5in"
document.Info.Title = "Barcodes"
document.DefaultPageSetup.RightMargin = ".21975in"
document.DefaultPageSetup.LeftMargin = ".21975in"
document.DefaultPageSetup.TopMargin = ".5in"
document.DefaultPageSetup.BottomMargin = ".5in"
'Adds a section to the document
Dim section As Section = document.AddSection()
'Add a barcode to the document
Dim bc As Paragraph = section.AddParagraph("*12345*")
'Here is is the problem. How do I get this line to work with a private font collection?
bc.Format.Font.Name = "Free 3 of 9 Extended"
bc.Format.Font.Size = "20pt"
'Render the pdf document
Dim pdfRenderer As New PdfDocumentRenderer(False, PdfFontEmbedding.Always)
pdfRenderer.Document = document
pdfRenderer.RenderDocument()
'Save the pdf document to their "My Documents" folder
Dim filename As String = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Test.pdf"
pdfRenderer.PdfDocument.Save(filename)
Process.Start(filename)
End Sub
End Class