PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Feb 15, 2025 12:34 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Error on Linux machine.
PostPosted: Fri Jan 24, 2025 10:49 am 
Offline

Joined: Fri Aug 23, 2024 12:27 pm
Posts: 2
I have a NET 8 Blazor Server App running on a nginx reverse proxy server. I have PDFSharp installed and have a printing function created to print out a sheet. I tested this on my local machine and it works there. But when I deploy my app and print from the server, the print fails.

Here is the console error.

Error: System.NullReferenceException: Object reference not set to an instance of an object.
at PdfSharp.Fonts.OpenType.OpenTypeFontFace.CetOrCreateFrom(XFontSource fontSource)
at PdfSharp.Drawing.XGlyphTypeface..ctor(String key, XFontFamily fontFamily, XFontSource fontSource, XStyleSimulations styleSimulations)
at PdfSharp.Drawing.XGlyphTypeface.GetOrCreateFrom(String familyName, FontResolvingOptions fontResolvingOptions)
at PdfSharp.Drawing.XFont.Initialize()
at PdfSharp.Drawing.XFont..ctor(String familyName, Double emSize, XFontStyleEx style, XPdfFontOptions pdfOptions)
at PdfSharp.Drawing.XFont..ctor(String familyName, Double emSize, XFontStyleEx style)
at AutoHARP3HarpFantasy.Data.Classes.pCharStat.PrintCharacter() in /var/www/autoharponline/Data/Classes/pCharStat.cs:line 1220
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

and this is what line 1220 has

gfx.DrawString("Name:", new XFont(fontName, 20, XFontStyleEx.Bold), XBrushes.Black, 25, 20, XStringFormats.TopLeft);
It seems to be complaining about new XFont(fontName, 20, XFontStyleEx.Bold).

To give more context here the code around this line

try
{
gfx.DrawString("Name:", new XFont(fontName, 20, XFontStyleEx.Bold), XBrushes.Black, 25, 20, XStringFormats.TopLeft);
}
catch(Exception e)
{
fontName = "arial";
gfx.DrawString("Name:", new XFont(fontName, 20, XFontStyleEx.Bold), XBrushes.Black, 25, 20, XStringFormats.TopLeft);
}

Just to see if perhaps I misspelled the font for Arial I changed it to Uppercase "Arial" and tested. That didn't fix it. So I am at a loss as to what the error is telling me about this call. I have other gfx calls before this so gfx should not be null here.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 26, 2025 5:33 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 350
davidklecker wrote:
To give more context here the code around this line
Not enough context.
Try PDFsharp 6.2.0 Preview 2.
Error comes from "new XFont(...)" - make sure your FontResolver can handle the font you need.

See also:
http://forum.pdfsharp.net/viewtopic.php?f=2&t=832

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


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

All times are UTC


Who is online

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