View previous topic :: View next topic |
Author |
Message |
pman
Joined: 14 Feb 2008 Posts: 2
|
Posted: Thu Feb 14, 2008 7:30 pm Post subject: help Embed ttf Font from a file |
|
|
Dim fn As System.Drawing.Font
fn = New Font(ffUtopia, 14, GraphicsUnit.World)
gfx.DrawString(stmp, XPdfFont, XBrushes.Black, xStart, yStart)
i get a "Object Reference not set to an instance of an object" error |
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: Mon Feb 18, 2008 8:01 am Post subject: |
|
|
PDFsharp 1.0 requires some changes to fully support private font collections.
Changes will be published with PDFsharp 1.1.
Recommended workaround: install the TTF file. _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
pman
Joined: 14 Feb 2008 Posts: 2
|
Posted: Tue Feb 19, 2008 3:37 pm Post subject: thanks |
|
|
Hey Thanks Thomas
a quick question... will it only work with TTF fonts?
thanks
do you have a sample on how to reference it ...thanks |
|
Back to top |
|
|
jmiko
Joined: 09 Feb 2009 Posts: 3
|
Posted: Mon Feb 09, 2009 2:18 am Post subject: |
|
|
I cannot embed private fonts. I have version 1.2. Has this been added? |
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: Mon Feb 09, 2009 11:23 am Post subject: |
|
|
Look for XPrivateFontCollection. _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
jmiko
Joined: 09 Feb 2009 Posts: 3
|
Posted: Mon Feb 09, 2009 11:07 pm Post subject: |
|
|
I am using the XPrivateFontCollection but it will not embed the fonts. I will try to post the code I'm using later.
Are there any samples? |
|
Back to top |
|
|
jmiko
Joined: 09 Feb 2009 Posts: 3
|
Posted: Mon Feb 09, 2009 11:21 pm Post subject: |
|
|
Ok I feel stupid now. I got it working
Code: | string pdfFileName = @"c:\test.pdf";
string fontFileName = @"c:\daniel.ttf";
XPrivateFontCollection privateFonts = new XPrivateFontCollection();
byte[] fontData = File.ReadAllBytes(fontFileName);
privateFonts.AddMemoryFont(fontData, fontData.Length, "Daniel", false, false);
using (PdfDocument doc = new PdfDocument())
{
PdfPage page = doc.AddPage();
using (XGraphics gfx = XGraphics.FromPdfPage(page))
{
XPrivateFont pfont = privateFonts.FindFont("Daniel", false, false);
XPdfFontOptions fontOptions = new XPdfFontOptions(PdfFontEncoding.WinAnsi, PdfFontEmbedding.Always);
FontFamily family = new FontFamily("Daniel", privateFonts.PrivateFontCollection);
XFont xfont = new XFont(family, 18, XFontStyle.Regular, fontOptions, privateFonts);
gfx.DrawString("Hello World", xfont, Brushes.Black, 50, 50);
}
doc.Save(pdfFileName);
}
System.Diagnostics.Process.Start(pdfFileName); |
|
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: Tue Feb 10, 2009 9:19 am Post subject: |
|
|
Thank you for the sample code.
XPrivateFontCollection is not yet covered by our samples. _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
|