HTML-Renderer
HTML-Renderer copied to clipboard
When using version PDFSharp 1.50.4545.0 type initializer throws an exception for adapters
Works fine when I revert back to PDFSharp version 1.32.3057. However, as soon as I update to version 1.50 I get type initializer error for: var pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf("
text
", PdfSharp.PageSize.A4);The error says "adapters are obsolete and not implemented anymore"
I also get this issue when using the HTMLRenderer. I will try reverting to PDFSharp version 1.32.3057 to see if I can work around this issue.
HtmlRenderer 1.51 should work with PdfSharp 1.50. When I say "should" I mean I am actively using it without those errors. If you really want help, post the full exception information showing the stack trace.
I'm getting a similar error. Here is the stack trace:
[InvalidOperationException: Obsolete and not implemted any more.] PdfSharp.Drawing.XFontFamily.get_Families() +46 TheArtOfDev.HtmlRenderer.PdfSharp.Adapters.PdfSharpAdapter..ctor() in d:\source\github\HTML-Renderer\Source\HtmlRenderer.PdfSharp\Adapters\PdfSharpAdapter.cs:44 TheArtOfDev.HtmlRenderer.PdfSharp.Adapters.PdfSharpAdapter..cctor() in d:\source\github\HTML-Renderer\Source\HtmlRenderer.PdfSharp\Adapters\PdfSharpAdapter.cs:33
[TypeInitializationException: The type initializer for 'TheArtOfDev.HtmlRenderer.PdfSharp.Adapters.PdfSharpAdapter' threw an exception.] TheArtOfDev.HtmlRenderer.PdfSharp.Adapters.PdfSharpAdapter.get_Instance() in d:\source\github\HTML-Renderer\Source\HtmlRenderer.PdfSharp\Adapters\PdfSharpAdapter.cs:57 TheArtOfDev.HtmlRenderer.PdfSharp.HtmlContainer..ctor() in d:\source\github\HTML-Renderer\Source\HtmlRenderer.PdfSharp\HtmlContainer.cs:43 TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(String html, PdfGenerateConfig config, CssData cssData, EventHandler
1 stylesheetLoad, EventHandler
1 imageLoad) in d:\source\github\HTML-Renderer\Source\HtmlRenderer.PdfSharp\PdfGenerator.cs:110 Uid.Web.Controllers.<Export>d__8.MoveNext() in C:\Users\dansmith\Code\Uid.Web\Controllers\PersonasController.cs:122 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 ...
Using ILSpy I can see that version 1.50 of PdfSharp throws an exception on PdfSharp.Drawing.XFontFamily.Families, and has "Use platform API directly" in the method's Obsolete attribute. Version 1.32 has valid code in the property accessor.
Upgrading HtmlRenderer.* to 1.5.1-beta1 does not generate this error.
I am also getting the same error. Anyone got help or fixed it ?
I reverted back to PDFSharp version 1.32.3057. It is working fine now.
Also I am using HtmlRenderer.PdfSharp version 1.5.0.6.
I don't think you guys use using the very latest HtmlRenderer code. 1.5.0.6 did not work with PdfSharp 1.50. There was a change made in 2016 to fix the exception in the PdfSharpAdapter constructor. The code in the constructor should look like this:
private PdfSharpAdapter()
{
AddFontFamilyMapping("monospace", "Courier New");
AddFontFamilyMapping("Helvetica", "Arial");
var families = new InstalledFontCollection();
foreach (var family in families.Families)
{
AddFontFamily(new FontFamilyAdapter(new XFontFamily(family.Name)));
}
}
Again, you need HtmlRenderer 1.5.1-beta1 or later to use PdfSharp 1.50. Note the latest PdfSharp, last I checked, was 1.50-beta5.
Would like to upgrade to PdfSharp 1.50, but at the moment I can't because of this issue, and through policy can't update to a beta version. 1.5.1-beta1 has been out for 2.5 years so far - is it possible that any issues will have been shaken out by now and a full release built? Thanks for the effort in producing this library, it is appreciated, and although it would be nice to see this, I understand it may take time...
Was this ever resolved? Thanks
Also wondering if this was ever resolved?
It seems reverting back to PDFSharp version 1.32.3057 should work? (I haven't tested this yet, just assuming this was the fix).
Thanks
Hi all,
I resolved this problem just by updating HtmlRenderer.PdfSharp like this:
Install-Package HtmlRenderer.PdfSharp -Version 1.5.1-beta1
I'm having the same problem using the newest versions of both PdfSharp(1.50.5147) and HtmlRenderer(1.5.0.6) using .NET 4.7.2
I'm having the same problem using the newest versions of both PdfSharp(1.50.5147) and HtmlRenderer(1.5.0.6) using .NET 4.7.2
thanks that was useful
If anyone has this error using this nuget in docker (Linux) then you have this error because PDFSharp uses System.Drawing.Common which works only in Windows. Fortunately there is a solution to this. Firstly install latest version of HtmlRenderer.PdfSharp.NetStandard2 (for me 1.5.1.1). Then look at this comment:
https://stackoverflow.com/a/73977430/14332640
In summary you need to install libgdiplus inside docker and add
<RuntimeHostConfigurationOption Include="System.Drawing.EnableUnixSupport" Value="true" />
inside
<ItemGroup>
tags.
inside every .csproj file of solution (one per project). Works like a charm!
Still the problem: using the newest versions of PdfSharp(1.50.5147) and HtmlRenderer(1.5.0.6) using .NET 4.8.0 This failure looks like verry olde one. Any date of fixing? I cannot downgrade because of using PDFsharp-MigraDoc
I'm now running into the same problem, this is open for quite a while, any new news beside downgrading or going to a beta?