PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Tue Jul 01, 2025 5:37 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sat May 24, 2025 8:20 am 
Offline

Joined: Tue Nov 01, 2022 3:34 pm
Posts: 5
Hello,

I have upgraded to PDFSharp vers 6.2.0 and everything works fine locally in Visual Studio on my Windows 11 PC, where I am working on a .NET Framework 4.7.2 Project. In Global.asax.cs I have set GlobalFontSettings.UseWindowsFontsUnderWindows = true.
I can also run my application under localhost.

But when I deploy the program to a Windows Server - I got an error already from the beginning when I run the program from that server via a local browser, which is mentioned here:

Image

So how to handle this error?

Thanks for advice.

Best regards


Top
 Profile  
Reply with quote  
PostPosted: Mon May 26, 2025 6:47 am 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1051
Location: CCAA
Hi!
mce wrote:
In Global.asax.cs I have set GlobalFontSettings.UseWindowsFontsUnderWindows = true.
Why do you call it there?
Why don't you set it just before using PDFsharp functions for the first time?

The error message you get does not look PDFsharp-related.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Tue May 27, 2025 9:31 am 
Offline

Joined: Tue Nov 01, 2022 3:34 pm
Posts: 5
Hello,

Thank you for the tip...

But unfortunately I still got an error - but now it is a new one...

I have make my code in this way for the first time I am using PDFSharp...:

Code:
            GlobalFontSettings.UseWindowsFontsUnderWindows = true;
            PdfDocument document = new PdfDocument();


I have only set this variable once in my pogram - but when I am running this first place, I am getting this error:

"Must not change UseWindowsFontsUnderWindows after it was once set or got."

And my stacktrace is as the following:

StackTrace
LineNumber: 215
ColumnNumber: 25
MethodName: set_UseWindowsFontsUnderWindows
FileName: D:\THHO\Repos\PDFsharp\src\foundation\src\PDFsharp\src\PdfSharp\Fonts\GlobalFontSettings.cs
NativeOffset: 157
ILOffset: 77

Any advice to avoid this error?

Best regards.


Top
 Profile  
Reply with quote  
PostPosted: Thu May 29, 2025 7:53 am 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1051
Location: CCAA
Make sure the line "GlobalFontSettings.UseWindowsFontsUnderWindows = true;" is the only reference to that variable and make sure that code executes before any document is created.
Maybe you have to restart the application pool after making code changes.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Fri May 30, 2025 8:11 am 
Offline

Joined: Tue Nov 01, 2022 3:34 pm
Posts: 5
Hello again,

Thank you very much for the answer - it has really lead me to a solution ...

I have now tested it under different circumstances - and it seems that I can get it to work very well... But I have a very last question which I will try to ask here: What will be the best and most stable solution for my webapplication be: To run this line of code only once in the application lifecycle - or only once pr. "server lifecycle" (meaning that I only need to run this line of code when my webapplication is restarted and maybe the Application Pools restarted too)?

And a further question: Will I in the future need to restart the Application Pools everytime I update the server with new code for my site (maybe including new PDFSharp documents)?

I hope that I have maked this question clear to understand ...

Regards Michael


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 02, 2025 8:18 am 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1051
Location: CCAA
mce wrote:
And a further question: Will I in the future need to restart the Application Pools everytime I update the server with new code for my site (maybe including new PDFSharp documents)?
The application pool will load a DLL once and will keep it.
"UseWindowsFontsUnderWindows" is a global variable that exists once and that can be set only once. It is shared by all web applications using the App Pool. To change the value of that variable, you can unload the DLL by killing the app pool.

When you provide a new DLL with your web application, the web server should notice that and should load the new DLL (just guessing).

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

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