Enabling unicode always displays fonts as Arial Bold

Dec 3, 2010 at 5:30 PM
Edited Dec 3, 2010 at 5:30 PM

Hello,

We are using the latest version of silverPDF. I posted to the PDFSharp forum here: http://forum.pdfsharp.net/viewtopic.php?f=2&t=1456 about the fact that on our system, enabling Unicode always displays fonts as Arial Bold, even if the font style is set to Regular. A PDFSharp contributor sent some example code that works for him (i.e. regular font displayed regular), but it doesn't work for us (regular font displayed in bold).

Can someone confirm/deny whether this is a silverPDF problem? Here is the code (see the link above for more details):

 

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);
}

 

Many thanks

Ed

Apr 4, 2011 at 4:24 PM

hi Ed,

i've got the same problem.

 

Manni

Jun 4, 2011 at 10:24 AM
Edited Jun 4, 2011 at 10:29 AM

Hi Ed and Manni,

It's now about 6 months later than when Ed posted his problem and unfortunately I must say that I have the same problem.

I am using Lightswitch and I want to print and I decided to use SilverPDF.

All was going well untill I wanted to display the euro sign, which it replaced with a ?. On the PDFsharp forum I was told I needed to embed the font. So what I did was:

                    XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);//without fontembedding no eurosign!!
                    XFont font = new XFont(FontName, 12, XFontStyle.Regular, options);

and indeed I now do get the euro sign, but all is bold.....

 

Did any of you (or perhaps someone else) find out how to overcome this problem??

And changing the font to for example Courier, which should really show, doesn't make any difference, so indeed it also seems as if a fixed font is being used.

 

Kind regards,

 

 

Clemens Linders

 

Jun 5, 2011 at 1:44 AM

In the silverPDF.dll is one font embedded (arialbd.ttf) that is used. If you want other fonts embedded, you can add another file (for examle arial.ttf for regular font) and register the stream in the FontPool.

Jun 7, 2011 at 1:12 PM
Edited Jun 7, 2011 at 1:17 PM

Yes, we used the same technique. We hadn't realised that arialbd.ttf was embedded for free so we embedded it again :)

 

static PdfHelper()
{
    var fs = Application.GetResourceStream(new Uri("/path/to/embedded/resources/ARIAL.TTF", UriKind.RelativeOrAbsolute)).Stream;
    FontPool.Register(fs, "ArialNormal");

    fs = Application.GetResourceStream(new Uri("/path/to/embedded/resources/ARIALBD.TTF", UriKind.RelativeOrAbsolute)).Stream;
    FontPool.Register(fs, "ArialBold");
}

public PdfHelper()
{
    ....

this.NormalFont = new XFont("ArialNormal", 8, XFontStyle.Regular, new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always)); this.BoldFont = new XFont("ArialBold", 8, XFontStyle.Regular, new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always)); }