PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Sep 07, 2024 3:22 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: Thu Apr 25, 2013 11:29 pm 
Offline

Joined: Sun Jun 24, 2012 3:07 pm
Posts: 4
hi.

XPrivateFontCollection pfc = new XPrivateFontCollection();


i have pfc.addfont() but not pfc.add().

why? and how to have it.

stephane


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 28, 2013 2:27 pm 
Offline

Joined: Sun Jun 24, 2012 3:07 pm
Posts: 4
I try that but i have alway the same error.
2 weeks that i try anything :(

Image



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


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 29, 2013 10:02 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3109
Location: Cologne, Germany
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

_________________
Regards
Thomas Hoevel
PDFsharp Team


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: Google [Bot] and 93 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