Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5953255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:47:56+00:00 2026-05-22T17:47:56+00:00

We use PDFSharp (the GDI+ build) in one of our web applications. In one

  • 0

We use PDFSharp (the GDI+ build) in one of our web applications. In one PDF exporter we’re using a non-system truetype font and it works like a charm in our dev environment but crashes when we run it in production.

The key difference (I think) between our dev and production is that our production servers are running on Windows Server 2008 64bit while our dev is running 2008 32bit. I wrote a tiny test program to debug.

try
{
    new XFont("ocrb10", 10, XFontStyle.Regular, new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always));
}
catch (Exception exc) { Console.WriteLine(exc.StackTrace); }

The error message is InvalidOperationException: Internal error. Font data could not retrieved.

at PdfSharp.Fonts.OpenType.FontData.CreateGdiFontImage(XFont font, XPdfFontOptions options)
at PdfSharp.Fonts.OpenType.FontData..ctor(XFont font, XPdfFontOptions options)
at PdfSharp.Fonts.OpenType.OpenTypeDescriptor..ctor(XFont font, XPdfFontOptions options)
at PdfSharp.Fonts.OpenType.OpenTypeDescriptor..ctor(XFont font)
at PdfSharp.Fonts.FontDescriptorStock.CreateDescriptor(XFont font)
at PdfSharp.Drawing.XFont.get_Metrics()
at PdfSharp.Drawing.XFont.Initialize()
at PdfSharp.Drawing.XFont..ctor(String familyName, Double emSize, XFontStyle style, XPdfFontOptions pdfOptions)

I built PDFSharp from source and added some debug code in order to understand what’s happening. The problem is that the pinvoke call to GetFontData returns -1 (GDI_ERROR). The PdfSharp author has added comments about this in FontData.cs where the error occurrs (search for GDI_ERROR) but he didn’t find a proper resolution either.

// Line 138 in FontData.cs, this GetFontData returns -1 here when 
// running as a web application on a 64bit windows host (regardles of WOW64
// being enabled or not)
int size = NativeMethods.GetFontData(hdc, 0, 0, null, 0);

Now, the problem for me is that I am unable to reproduce this error in any environment when I run the code as an console application. I’ve tried toggling WOW64 on and off for the application pool and I’ve tried running the application pool under my own credentials in case there was any permission related problems but to no avail.

The WPF build of PDFSharp works great btw and it’s quite possible that we’ll just switch to that if we don’t find any solution but I’m really curious as to what could cause this.

Can anyone please help me with further debugging steps? In what ways are the environment different when running in IIS/ASP.NET versus a console application when it comes to PInvokes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:47:56+00:00Added an answer on May 22, 2026 at 5:47 pm

    It is very common for developers to rely on GDI+ for retrieving font metrics, however according to MSDN:

    GDI+ functions and classes are not
    supported for use within a Windows
    service. Attempting to use these
    functions and classes from a Windows
    service may produce unexpected
    problems, such as diminished service
    performance and run-time exceptions or
    errors.

    In FontData.cs I found the following:

    #if GDI
    100    /// <summary>
    101    /// Create the font image using GDI+ functionality.
    102    /// </summary>
    103    void CreateGdiFontImage(XFont font, XPdfFontOptions options/*, XPrivateFontCollection privateFontCollection*/)
    104    {
    105      System.Drawing.Font gdiFont = font.RealizeGdiFont();
    106      NativeMethods.LOGFONT logFont;
    ...
    

    This is why GDI+ build of PDFSharp is not working in services while the WPF build does work as you stated on your question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use MigraDoc/PdfSharp to create and store PDF documents. Is there a
I have a program that is manually generating a PDF using PDFsharp in C#.
I am using an external DLL (pdfsharp) to open (then manipulate) lots of PDF
I am using the PDFsharp (which is used to generate pdf file in asp.net),
Use Case I need to package up our kml which is in a String
Use http://jobs.sitesixteen.com/ for reference. I'm using YQL for the city, state auto-complete. IF you
use Parallel::ForkManager; use LWP::Simple; my $pm=new Parallel::ForkManager(10); our $a =0; @LINK=( 10,203, 20, 20
Use case: User clicks a link, a modal window is displayed containing one big
I use PdfSharp/MigraDoc to create and view documents in an application. I use the
I am using PDFSharp in my c# project. In my previous work place I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.