PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Enabling unicode always displays fonts as Arial Bold https://forum.pdfsharp.net/viewtopic.php?f=2&t=1456 |
Page 1 of 1 |
Author: | edwiles [ Thu Dec 02, 2010 2:29 pm ] |
Post subject: | Enabling unicode always displays fonts as Arial Bold |
Hello, I've enabled Unicode support in PDFSharp as described on your wiki, and applied it to 3 different fonts which we then use with the XGraphics.DrawString method. Set-up code as follows: Code: XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); this.NormalFont = new XFont("Arial", 8, XFontStyle.Regular, options); this.BoldFont = new XFont("Arial", 8, XFontStyle.Bold, options); this.TitleFont = new XFont("Arial", 12, XFontStyle.Bold, options); However upon loading the resulting document into Acrobat Reader, all fonts are consistently in bold, even the NormalFont. What's more, as an experiment I changed all of the fonts to "Times New Roman" and XFontStyle.Regular - and even then the font consistently displays as Arial Bold! (at least, it's definitely not a serif font) Without setting the font options, the NormalFont displays correctly. For the code above, the Fonts tab in Acrobat Reader document properties lists the following: Arial (Embedded Subset). Type: TrueType (CID). Encoding: Identity-H. Arial,Bold (Embedded Subset). Type: TrueType (CID). Encoding: Identity-H. Whereas without the font options, it displays the following: Arial. Type: TrueType. Encoding: Ansi. Actual Font: ArialMT. Actual Font Type: TrueType Arial,Bold. Type: TrueType. Encoding: Ansi. Actual Font: ArialMT. Actual Font Type: TrueType I would attach the problematic document but it's a bit commercially sensitive for a public forum... Hope there's enough information here. Many thanks Ed |
Author: | Thomas Hoevel [ Thu Dec 02, 2010 2:57 pm ] | ||
Post subject: | Re: Enabling unicode always displays fonts as Arial Bold | ||
Hi! I just ran a modified version of the PDFsharp Unicode sample: Code: static void Main() { // Create new document PdfDocument document = new PdfDocument(); // Set font encoding to unicode XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); //XFont font = new XFont("Times New Roman", 12, XFontStyle.Regular, options); XFont normalFont = new XFont("Arial", 8, XFontStyle.Regular, options); XFont boldFont = new XFont("Arial", 8, XFontStyle.Bold, options); XFont titleFont = new XFont("Arial", 12, XFontStyle.Bold, options); // Draw text in different languages for (int idx = 0; idx < texts.Length; idx++) { PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XTextFormatter tf = new XTextFormatter(gfx); tf.Alignment = XParagraphAlignment.Left; //tf.DrawString(texts[idx], font, XBrushes.Black, // new XRect(100, 100, page.Width - 200, 600), XStringFormats.TopLeft); tf.DrawString(texts[idx], normalFont, XBrushes.Black, new XRect(100, 100, page.Width - 200, 600), XStringFormats.TopLeft); tf.DrawString(texts[idx], boldFont, XBrushes.Black, new XRect(100, 300, page.Width - 200, 600), XStringFormats.TopLeft); tf.DrawString(texts[idx], titleFont, XBrushes.Black, new XRect(100, 500, page.Width - 200, 600), XStringFormats.TopLeft); } const string filename = "Unicode_tempfile.pdf"; // Save the document... document.Save(filename); // ...and start a viewer. Process.Start(filename); } Everything worked as expected (see attached file).
|
Author: | edwiles [ Thu Dec 02, 2010 4:26 pm ] |
Post subject: | Re: Enabling unicode always displays fonts as Arial Bold |
Thomas, Thanks very much for your counter-demonstration! I copied and pasted your code, and for us the normal font still comes out as bold.... ...and then I noticed that actually we are using silverPDF. My mistake! I will post there. Thanks again Ed |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |