PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 7:14 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Fri Mar 01, 2024 7:59 am 
Offline

Joined: Fri Mar 01, 2024 7:35 am
Posts: 7
Hi,

I have upgraded from PDFSharp 1.5 to 6.0 and it has not been a smooth transition I am sorry to say.

First of all I had some troubles with getting the assets to my solution. Download-assets.ps1 did not help at all. We are using the Font "Roboto" and Download-assets.ps1 didn't help with that. I had to download the font from google and manually put it in a folder where I then had to tell my new FontResolver-class to find it.

I got it to work locally on my machine and deployed to our first test environment.

Next problem: the fonts does not deploy automatically. I have to copy the fonts manually to each of our test-, qa-, education- and production environments. And we have 8 of those environments. I guess this is solvable in our CI/CD-pipeline somehow.

Next problem: now the fonts are located on the server, then I get this error when reading the fonts and creating the fonts:

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)

I don't know whats going on here. As I wrote, it works locally for me, but not when deployed to our first development-server.

It fails on the line:

XFont font = new XFont("Roboto", 80, XFontStyleEx.Bold);

the line before that is:

GlobalFontSettings.FontResolver = new RobotoFontResolver();


I am seriously thinking about downgrading to PDFSharp 1.5 again, where assets wheren't an issue.

We are using .NET 6 btw.

thanks for any help.
Rickard


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 01, 2024 10:24 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 916
Location: CCAA
Hi!
RickSan wrote:
I have upgraded from PDFSharp 1.5 to 6.0 and it has not been a smooth transition I am sorry to say.
Use the GDI build of PDFsharp 6.0 and font handling will be the same as with PDFsharp 1.5.

You only have to use Download-assets.ps1 when you want to compile PDFsharp.
Why not simply use the existing NuGet packages?

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 01, 2024 11:27 am 
Offline

Joined: Fri Mar 01, 2024 7:35 am
Posts: 7
TH-Soft wrote:
Hi!
Use the GDI build of PDFsharp 6.0 and font handling will be the same as with PDFsharp 1.5.

You only have to use Download-assets.ps1 when you want to compile PDFsharp.
Why not simply use the existing NuGet packages?


Okay, now we're on to something! Clearly I'm doing something wrong here.
I am using the existing nuget packages, not compiling on my own. But the nuget package are not finding the assets (the font Roboto in my case) after upgrading.
I upgraded the nuget package "PDFSharp" from 1.5 til 6.0.0. Is the solution to change nuget package to "PDFSharp-GDI" version 6.0.0?
I thought that "PDFSharp-GDI" was made for use on windows clients (Windows Forms). In our case PDFSharp is run on the backend servers, not on clients.
But I guess it could work anyway.
I will try that out, see what happends.

Thanks for the reply.


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 01, 2024 11:37 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 916
Location: CCAA
PDFsharp 1.5 uses GDI to load fonts from the Windows directory. So does PDFsharp-GDI 6.0.

PDFsharp (Core) 6.0 relies on the FontResolver you supply.

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 01, 2024 2:03 pm 
Offline

Joined: Fri Mar 01, 2024 7:35 am
Posts: 7
TH-Soft wrote:
PDFsharp 1.5 uses GDI to load fonts from the Windows directory. So does PDFsharp-GDI 6.0.

PDFsharp (Core) 6.0 relies on the FontResolver you supply.


Thanks! Then I'll change nuget package to PDFsharp-GDI.

Thank you for clearing this up for me.

/Rickard


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 01, 2024 2:48 pm 
Offline

Joined: Fri Mar 01, 2024 7:35 am
Posts: 7
TH-Soft wrote:
PDFsharp 1.5 uses GDI to load fonts from the Windows directory. So does PDFsharp-GDI 6.0.

PDFsharp (Core) 6.0 relies on the FontResolver you supply.



Sorry, it did not work as intended :(
Changing to PDFsharp-GDI requires me to change target framework to "net6.0-windows7.0". I can't do that.

"Error NU1202 Package PDFsharp-GDI 6.0.0 is not compatible with net6.0 (.NETCoreApp,Version=v6.0). Package PDFsharp-GDI 6.0.0 supports: net6.0-windows7.0 (.NETCoreApp,Version=v6.0)"

So it seems like I have to downgrade to PDFSharp 1.5 then?

I would like a version of PDFSharp that is compatible with .NET 6, and works like PDFSharp 1.5. It seems like that is to much to ask for.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 04, 2024 1:17 pm 
Offline

Joined: Fri Mar 01, 2024 7:35 am
Posts: 7
TH-Soft wrote:
PDFsharp 1.5 uses GDI to load fonts from the Windows directory. So does PDFsharp-GDI 6.0.

PDFsharp (Core) 6.0 relies on the FontResolver you supply.


Since I couldn't migrate to PDFSharp-GDI, I guess I have to choose between downgrading to 1.5 again, or trying to find out why I am getting System.NullReferenceException inside PdfSharp.Fonts.OpenType.OpenTypeFontface.CetOrCreateFrom()..

And since I have no clue to where to start on that, downgrading seems to be the easiest option. Even though I really don't want to.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 04, 2024 2:17 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 916
Location: CCAA
RickSan wrote:
And since I have no clue to where to start on that, downgrading seems to be the easiest option.
PDFsharp 1.5 is from 2019 and targets .NET 2.0.

Reporting issues against PDFsharp 6.x:
https://docs.pdfsharp.net/General/IssueReporting.html

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


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 04, 2024 11:29 pm 
Offline

Joined: Fri Mar 01, 2024 7:35 am
Posts: 7
TH-Soft wrote:
RickSan wrote:
And since I have no clue to where to start on that, downgrading seems to be the easiest option.
PDFsharp 1.5 is from 2019 and targets .NET 2.0.

Reporting issues against PDFsharp 6.x:
https://docs.pdfsharp.net/General/IssueReporting.html


Yes, I know. It's not ideal.

Now I tried the preview of PDFSharp-GDI 6.1.0-preview-1, and that does target .net6.0 it seems like. Maybe I'll switch to that. Any idea when a stable version of 6.1.0 is coming?

Thanks again for all help.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 05, 2024 8:44 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 916
Location: CCAA
RickSan wrote:
view of PDFSharp-GDI 6.1.0-preview-1, and that does target .net6.0 it seems like.
It targets net6.0-windows7.0.

RickSan wrote:
Any idea when a stable version of 6.1.0 is coming?
The next preview should come in a few days, but no ETA yet for a stable version.

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


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 05, 2024 8:48 am 
Offline

Joined: Fri Mar 01, 2024 7:35 am
Posts: 7
TH-Soft wrote:
RickSan wrote:
view of PDFSharp-GDI 6.1.0-preview-1, and that does target .net6.0 it seems like.
It targets net6.0-windows7.0.


Yeah, I saw that. But it also targets .NET Framework 4.7.2 so I guess that's why it works for me.

RickSan wrote:
Any idea when a stable version of 6.1.0 is coming?
The next preview should come in a few days, but no ETA yet for a stable version.[/quote]

OK, thanks.


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

All times are UTC


Who is online

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