PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 16, 2024 9:14 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Fri Sep 30, 2011 2:07 pm 
Offline

Joined: Mon Sep 12, 2011 1:09 pm
Posts: 23
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.


Top
 Profile  
Reply with quote  
PostPosted: Sat Oct 01, 2011 2:51 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 341
That's the right way: install them and use them.
Maybe you don't specify the correct font names (without bold, regular, etc.).

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 03, 2011 3:26 pm 
Offline

Joined: Mon Sep 12, 2011 1:09 pm
Posts: 23
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.


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 04, 2011 7:23 am 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 06, 2011 11:44 am 
Offline

Joined: Mon Sep 12, 2011 1:09 pm
Posts: 23
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.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 06, 2011 11:50 am 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 07, 2011 9:48 am 
Offline

Joined: Mon Sep 12, 2011 1:09 pm
Posts: 23
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 651 times
Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 18, 2011 1:49 pm 
Offline

Joined: Mon Sep 12, 2011 1:09 pm
Posts: 23
Any solution found for this font which was attached in previous reply ?

Please let me know.

I am looking for your reply.


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 18, 2011 3:32 pm 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 160 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