PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
XPrivateFontCollection privateFontCollection = new XPrivate https://forum.pdfsharp.net/viewtopic.php?f=2&t=2417 |
Page 1 of 1 |
Author: | steflavoie [ Thu Apr 25, 2013 11:29 pm ] |
Post subject: | XPrivateFontCollection privateFontCollection = new XPrivate |
hi. XPrivateFontCollection pfc = new XPrivateFontCollection(); i have pfc.addfont() but not pfc.add(). why? and how to have it. stephane |
Author: | steflavoie [ Sun Apr 28, 2013 2:27 pm ] |
Post subject: | Re: XPrivateFontCollection privateFontCollection = new XPriv |
I try that but i have alway the same error. 2 weeks that i try anything ![]() ![]() Font with the specified family name does not exist. thank Code: using System;
using System.Windows; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Diagnostics; using PdfSharp.Pdf; using PdfSharp.Drawing; namespace WindowsFormsApplication17 { public partial class Form1 : Form { readonly Dictionary<string, FontFamily> fontFamilies = new Dictionary<string, FontFamily>(StringComparer.InvariantCultureIgnoreCase); XPrivateFontCollection globalFontCollection = XPrivateFontCollection.Global; public Form1() { InitializeComponent(); } private void Form1_Load_1(object sender, EventArgs e) { new System.Windows.Application(); Uri uri = new Uri("pack://application:,,,/"); globalFontCollection.Add(uri, "./#Calligraphy_Pen.TTF"); // Create new document PdfDocument document = new PdfDocument(); // Set font embedding to Always XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); const string familyName1 = "Calligraphy Pen"; XFont font1 = new XFont(familyName1, 24, XFontStyle.Bold, options); gfx.DrawString("This is a Calligraphy Pen Private Font", font1, XBrushes.Black, 100, 100); string filename = "test_tempfile.pdf"; // Save the document... document.Save(filename); // ...and start a viewer. Process.Start(filename); } } } |
Author: | Thomas Hoevel [ Mon Apr 29, 2013 10:02 am ] |
Post subject: | Re: XPrivateFontCollection privateFontCollection = new XPriv |
Hi! The URI notation for fonts from resources is a bit tricky. The source package includes a fully working sample to get you going. A code snippet is on the sample site: http://www.pdfsharp.net/wiki/PrivateFonts-sample.ashx |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |