HTML-Renderer icon indicating copy to clipboard operation
HTML-Renderer copied to clipboard

Method not found: PdfSharp.Drawing.XGraphics PdfSharp.Drawing.XGraphics.CreateMeasureContext(PdfSharp.Drawing.XSize, PdfSharp.Drawing.XGraphicsUnit, PdfSharp.Drawing.XPageDirection)

Open dnsnx opened this issue 1 year ago • 2 comments

I have a fresh project Console App, .NET 8. I have installed PDFSharp 6.2.0-preview-1 and HtmlRenderer.PdfSharp (1.5.1-beta-1) and HtmlRenderer.Core (1.5.1-beta-1). My code is very simple from the readme.txt:

PdfDocument pdf = PdfGenerator.GeneratePdf("<p><h1>Hello World</h1>This is html rendered text</p>", PageSize.A4);
pdf.Save("C:\\Users\\username\\Downloads\\document.pdf");

When I debug the project, I get this exception:

System.MissingMethodException: 'Method not found: 'PdfSharp.Drawing.XGraphics PdfSharp.Drawing.XGraphics.CreateMeasureContext(PdfSharp.Drawing.XSize, PdfSharp.Drawing.XGraphicsUnit, PdfSharp.Drawing.XPageDirection)'.'

Here are some details:

Source: "HtmlRenderer.PdfSharp" StackTrace:

at TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.AddPdfPages(PdfDocument document, String html, PdfGenerateConfig config, CssData cssData, EventHandler1 stylesheetLoad, EventHandler1 imageLoad) at TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(String html, PdfGenerateConfig config, CssData cssData, EventHandler1 stylesheetLoad, EventHandler1 imageLoad) at TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(String html, PageSize pageSize, Int32 margin, CssData cssData, EventHandler1 stylesheetLoad, EventHandler1 imageLoad) at Program.<Main>$(String[] args) in C:\Company\Projects\C_Sharp\Test\GeneratePdf\GeneratePdf\Program.cs:line 12

I've created a new project with .NET Framework 4.7.2 and installed HtmlRenderer.PdfSharp (1.5.1-beta-1) and HtmlRenderer.Core (1.5.1-beta-1). Here the code works fine without error. Is it an issue with .NET?

Any help appriciated. Thanks in advance.

dnsnx avatar Oct 02 '24 06:10 dnsnx

I resolved this by removing the original library and letting this extension install it as it should.

FR33M0N7 avatar Jan 28 '25 13:01 FR33M0N7

I resolved this by removing the original library and letting this extension install it as it should.

@dnsnx @FR33M0N7 I hit this issue also, may I know how do you solve it?

geowong2022 avatar Apr 04 '25 10:04 geowong2022