PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jul 14, 2024 10:12 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 Dec 02, 2010 2:29 pm 
Offline

Joined: Thu Dec 02, 2010 2:15 pm
Posts: 2
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 02, 2010 2:57 pm 
Offline
PDFsharp Guru
User avatar

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


Attachments:
Unicode_testfile.zip [104.08 KiB]
Downloaded 624 times

_________________
Regards
Thomas Hoevel
PDFsharp Team
Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 02, 2010 4:26 pm 
Offline

Joined: Thu Dec 02, 2010 2:15 pm
Posts: 2
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


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: No registered users and 29 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