PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 2:31 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed May 29, 2024 12:46 pm 
Offline

Joined: Mon Aug 07, 2023 9:07 pm
Posts: 9
After installing PDFsharp-MigraDoc 6.1.0 from NuGet code

Code:
  static ReportTemplateBase()
  {
    GlobalFontSettings.FontResolver = new NewFontResolver();
  }


Throws error

Quote:
The type or namespace name 'NewFontResolver' could not be found (are you missing a using directive or an assembly reference?)


How to fix it?

Times New Roman and Arial .ttf files are copied to Debian to /usr/share/fonts/winfonts directory. How to use fonts in Debian from this directory for pdf creation.

Font files can copied to other directories if this helps.


Top
 Profile  
Reply with quote  
PostPosted: Wed May 29, 2024 12:58 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 950
Location: CCAA
See documentation:
https://docs.pdfsharp.net/General/Histo ... ntresolver

Quote:
Note that NewFontResolver was renamed to SnippetsFontResolver with version 6.1.0 Preview 1. Note that SnippetsFontResolver is no longer available as of version 6.1.0 Preview 3.


Functionality from NewFontResolver was moved to PlatformFontResolver, so Arial and Times New Roman should work under Linux without setting a font resolver if they worked with the NewFontResolver.

See also:
https://docs.pdfsharp.net/PDFsharp/Topi ... About.html

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


Top
 Profile  
Reply with quote  
PostPosted: Wed May 29, 2024 1:28 pm 
Offline

Joined: Mon Aug 07, 2023 9:07 pm
Posts: 9
I removed this code and run application from Visual Studio IDE in Windows 11. It throws error

Quote:
System.InvalidOperationException
HResult=0x80131509
Message=No appropriate font found for family name 'Calibri'. Implement IFontResolver and assign to 'GlobalFontSettings.FontResolver' to use fonts. See https://docs.pdfsharp.net/link/font-resolving.html
Source=PdfSharp
StackTrace:
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 MigraDoc.DocumentObjectModel.TextMeasurement.Realize() in C:\raamat\eevaweb\Store\Reporting\VFPConverter\Class.cs:line 154
at MigraDoc.DocumentObjectModel.TextMeasurement.MeasureString(String text, UnitType unitType) in C:\raamat\eevaweb\Store\Reporting\VFPConverter\Class.cs:line 74
at MigraDoc.DocumentObjectModel.TextMeasurement.MeasureString(String text) in C:\raamat\eevaweb\Store\Reporting\VFPConverter\Class.cs:line 114
...


Windows has Calibri font installed. Using NewFontresolver() it worked in Windows and Linux.
How to fix this?
If it is not possible to use Calibri, some other font can used so that pdf is created.

How to force PDFSharp to silently use Calibri or some other font without throwing error?


Top
 Profile  
Reply with quote  
PostPosted: Wed May 29, 2024 1:41 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 950
Location: CCAA
andrus wrote:
If it is not possible to use Calibri, some other font can used so that pdf is created.
Out of the box, you can use fonts like Arial, Verdana, Times New Roman, and some others. See code here:
https://github.com/empira/PDFsharp/blob ... esolver.cs

Calibri is not on that list. Either grab the code from NewFontResolver from version 6.0 or write a FontResolver that supports Calibri or use other fonts like Verdana and Arial.

_________________
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  [ 4 posts ] 

All times are UTC


Who is online

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