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);
}
}
}