PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

How to use the font CHSans-Bold.ttf in pdfsharp's pdf ?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1801
Page 1 of 1

Author:  Vadivelan [ Fri Sep 30, 2011 2:07 pm ]
Post subject:  How to use the font CHSans-Bold.ttf in pdfsharp's pdf ?

I have installed the CHSans-Bold.ttf,CHSans-Regular.ttf,CHSans-Light.ttf and checked in Microsoft Word.
It is working fine in Word but not able to set this font in pdfsharp.

So what are the steps to do to use this font in pdfsharp ?

Please let me know.

Author:  () => true [ Sat Oct 01, 2011 2:51 pm ]
Post subject:  Re: How to use the font CHSans-Bold.ttf in pdfsharp's pdf ?

That's the right way: install them and use them.
Maybe you don't specify the correct font names (without bold, regular, etc.).

Author:  Vadivelan [ Mon Oct 03, 2011 3:26 pm ]
Post subject:  Re: How to use the font CHSans-Bold.ttf in pdfsharp's pdf ?

I installed this font in Windows 7 and checked Microsoft Word which shows this installed font - CHSans-Light,CHSans-Bold,CHSans-Regular.

But the pdf does not show these fonts even after installation.

The below code is using for to create the font.

return new XFont("CHSans-Light",20.0,XFontStyle.Regular,new XPdfFontOptions(PdfSharp.Pdf.PdfFontEncoding.Unicode, PdfSharp.Pdf.PdfFontEmbedding.Always))
The result for this font which is below shows "Microsoft Sans Serif" not "CHSans-Light".But if the above code works for other fonts.Ex.If pass "Arial" then the below output is retreived as "Arial".

'"Microsoft Sans Serif"', 20.0
Bold: false
FontFamily: {PdfSharp.Drawing.XFontFamily}
GdiFamily: null
Height: 23
Italic: false
Metrics: {PdfSharp.Drawing.XFontMetrics}
Name: "Microsoft Sans Serif"
PdfOptions: {PdfSharp.Drawing.XPdfFontOptions}
Size: 20.0
Strikeout: false
Style: Regular
Underline: false


And i checked FontFamily.Families .there is no such font - CHSans-Light is listed out.
So please tell me how to add this font (CHSans-Light,etc,) to this FontFamily.Families.
Then it will work i believe.

Author:  Thomas Hoevel [ Tue Oct 04, 2011 7:23 am ]
Post subject:  Re: How to use the font CHSans-Bold.ttf in pdfsharp's pdf ?

Hi!
Vadivelan wrote:
So please tell me how to add this font (CHSans-Light,etc,) to this FontFamily.Families.
We don't have the fonts, therefore we cannot try anything.
Are these free fonts that are available for download somewhere?

Author:  Vadivelan [ Thu Oct 06, 2011 11:44 am ]
Post subject:  Re: How to use the font CHSans-Bold.ttf in pdfsharp's pdf ?

There is no specific site / link to download these fonts.

So i will share those fonts to you for trying them.

Please let me know how to attach them in this forum site.

Author:  Thomas Hoevel [ Thu Oct 06, 2011 11:50 am ]
Post subject:  Re: How to use the font CHSans-Bold.ttf in pdfsharp's pdf ?

Vadivelan wrote:
Please let me know how to attach them in this forum site.
ZIP 'em and attach 'em.
I think there is a limit of 256 kiB per attachment, so you may need more than one ZIP file.

Author:  Vadivelan [ Fri Oct 07, 2011 9:48 am ]
Post subject:  Re: How to use the font CHSans-Bold.ttf in pdfsharp's pdf ?

Please find attached the zip file for CHSans font to be installed in your system.

First install this font family then open the Microsoft Word and check this font is added in the font family list for confirming this font has been installed correctly.

Then try to use this font in pdf using pdfsharp.

Please let me know and give me a solution to make use of this font.

Attachments:
File comment: There are three types of this font - CHSans-Bold,Regular & Light.
CHSans font family.zip [175.73 KiB]
Downloaded 722 times

Author:  Vadivelan [ Tue Oct 18, 2011 1:49 pm ]
Post subject:  Re: How to use the font CHSans-Bold.ttf in pdfsharp's pdf ?

Any solution found for this font which was attached in previous reply ?

Please let me know.

I am looking for your reply.

Author:  Thomas Hoevel [ Tue Oct 18, 2011 3:32 pm ]
Post subject:  Re: How to use the font CHSans-Bold.ttf in pdfsharp's pdf ?

Hi!

I'm sorry for the late reply, I've pretty busy when you posted the fonts.
Must have forgotten it - so it's good you asked again.

I downloaded the fonts, double-clicked them and then clicked "Install".

Here's my test code (a modified HelloWorld sample):
Code:
// Create a new PDF document
PdfDocument document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";

// Create an empty page
PdfPage page = document.AddPage();

// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);

XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
//XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.WinAnsi, PdfFontEmbedding.None);

// Create a font
//XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
XFont font = new XFont("CHSans-Light", 20, XFontStyle.Regular, options);

// Draw the text
gfx.DrawString("Hello, World! ABCDEFGHIJKLMNOPQRSTUVWXYZ", font, XBrushes.Black,
  new XRect(0, 0, page.Width, page.Height / 3),
  XStringFormats.Center);
gfx.DrawString("Hello, World! abcdefghijklmnopqrstuvwxyz", font, XBrushes.Black,
  new XRect(0, 30, page.Width, page.Height / 3),
  XStringFormats.Center);

font = new XFont("CHSans-Regular", 20, XFontStyle.Regular, options);

// Draw the text
gfx.DrawString("Hello, World! ABCDEFGHIJKLMNOPQRSTUVWXYZ", font, XBrushes.Black,
  new XRect(0, page.Height / 3, page.Width, page.Height / 3),
  XStringFormats.Center);
gfx.DrawString("Hello, World! abcdefghijklmnopqrstuvwxyz", font, XBrushes.Black,
  new XRect(0, 30 + page.Height / 3, page.Width, page.Height / 3),
  XStringFormats.Center);

font = new XFont("CHSans-Bold", 20, XFontStyle.Regular, options);

// Draw the text
gfx.DrawString("Hello, World! ABCDEFGHIJKLMNOPQRSTUVWXYZ", font, XBrushes.Black,
  new XRect(0, 2 * page.Height / 3, page.Width, page.Height / 3),
  XStringFormats.Center);
gfx.DrawString("Hello, World! abcdefghijklmnopqrstuvwxyz", font, XBrushes.Black,
  new XRect(0, 30 + 2 * page.Height / 3, page.Width, page.Height / 3),
  XStringFormats.Center);

// Save the document...
const string filename = "HelloWorld_tempfile.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);


I attach the generated PDF file. To me it looks as if the correct fonts are used (looking at Q, j and g). I made the test under Windows 7.

I don't see a problem in your code fragment. The fonts work here, so there is nothing wrong with them either.
Maybe it helps to remove and re-install the fonts.

Attachments:
HelloWorld_tempfile.zip [33.1 KiB]
Downloaded 608 times

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/