christiaanderidder / QuestPDF.Markdown

QuestPDF.Markdown allows rendering markdown into a QuestPDF document
MIT License
26 stars 5 forks source link

Compatiblities with QuestPdf 2024.3.0 #33

Closed danirzv closed 6 months ago

danirzv commented 7 months ago

Describe the bug When updated QuestPdf from 2023.12.3 to 2024.3.0-alpha and also updated QuestPdf.Markdown from 1.4.0 to 1.6.1 my pdf generation started to fail which were working fine before:

2024-02-20 09:57:21.757 +03:30 0HN1HRIBE07KE:0000000B [e5cea25becee742149f4f3d0c1746cfa] [FTL] - Username:  - VBI.Hub.Presentation.GlobalExceptionHandler - An unhandled exception has occurred while executing the request.
System.MissingMethodException: Method not found: 'QuestPDF.Infrastructure.IContainer QuestPDF.Fluent.BorderExtensions.BorderColor(QuestPDF.Infrastructure.IContainer, System.String)'.
   at QuestPDF.Markdown.MarkdownRenderer.ProcessContainerBlock(ContainerBlock block, IContainer pdf)
   at QuestPDF.Markdown.MarkdownRenderer.Compose(IContainer pdf)
   at QuestPDF.Fluent.ComponentExtensions.Component[T](IContainer element, T component, Action`1 handler)
   at QuestPDF.Fluent.ComponentExtensions.Component[T](IContainer element, T component)
   at QuestPDF.Markdown.MarkdownExtensions.Markdown(IContainer container, String markdown, MarkdownRendererOptions options)
   at VBI.Hub.Infrastructure.PdfGenerator.<>c__DisplayClass3_0.<Generate>b__3(RowDescriptor r) in C:\Git\VBI.Hub\VBI.Hub.Infrastructure\PdfGenerator.cs:line 86
   at QuestPDF.Fluent.RowExtensions.Row(IContainer element, Action`1 handler)
   at VBI.Hub.Infrastructure.PdfGenerator.<>c__DisplayClass3_0.<Generate>b__1(PageDescriptor pageHandler) in C:\Git\VBI.Hub\VBI.Hub.Infrastructure\PdfGenerator.cs:line 83
   at QuestPDF.Fluent.PageExtensions.Page(IDocumentContainer document, Action`1 handler)
   at VBI.Hub.Infrastructure.PdfGenerator.<>c__DisplayClass3_0.<Generate>b__0(IDocumentContainer pdf) in C:\Git\VBI.Hub\VBI.Hub.Infrastructure\PdfGenerator.cs:line 36
   at QuestPDF.Fluent.Document.Compose(IDocumentContainer container)
   at QuestPDF.Drawing.DocumentGenerator.ConfigureContent(IDocument document, DocumentSettings settings, Boolean useOriginalImages)
   at QuestPDF.Drawing.DocumentGenerator.RenderSingleDocument[TCanvas](TCanvas canvas, IDocument document, DocumentSettings settings)
   at QuestPDF.Drawing.DocumentGenerator.RenderDocument[TCanvas](TCanvas canvas, IDocument document, DocumentSettings settings)
   at QuestPDF.Drawing.DocumentGenerator.GeneratePdf(SkWriteStream stream, IDocument document)
   at QuestPDF.Fluent.GenerateExtensions.GeneratePdf(IDocument document)
   at QuestPDF.Fluent.GenerateExtensions.GeneratePdf(IDocument document, Stream stream)
   at VBI.Hub.Infrastructure.PdfGenerator.Generate(PdfGeneratorInput input) in C:\Git\VBI.Hub\VBI.Hub.Infrastructure\PdfGenerator.cs:line 34
   at VBI.Hub.Application.Features.GeneratePdfRequestHandler.Handle(GeneratePdfRequest request, CancellationToken cancellationToken) in C:\Git\VBI.Hub\VBI.Hub.Application\Features\GeneratePdf.cs:line 20
   at MediatR.Wrappers.RequestHandlerWrapperImpl`2.<>c__DisplayClass1_0.<Handle>g__Handler|0()
   at MediatR.Wrappers.RequestHandlerWrapperImpl`2.Handle(IRequest`1 request, IServiceProvider serviceProvider, CancellationToken cancellationToken)
   at MediatR.Mediator.Send[TResponse](IRequest`1 request, CancellationToken cancellationToken)
   at VBI.Hub.Presentation.Controllers.GeneralController.GeneratePdf(GeneratePdfRequest request, String fileName) in C:\Git\VBI.Hub\VBI.Hub.Presentation\Controllers\GeneralController.cs:line 48
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

Environment

MarcinZiabek commented 7 months ago

First of all, let me thank the QuestPDF.Markdown author for creating this library and actively maintaining it. You are doing an exceptional work!

I have looked at this issue and found a likely root cause. The recent QuestPDF version introduces an alternative way of specifying colors based on uint32 numbers (via the Infrastructure.Color struct). This allows us to reduce memory usage and improve performance slightly (as the library does not need to perform string parsing or cache's key hash calculation).

It is not a breaking change from a regular application perspective, as the Infrastructure.Color structure has an implicit string conversion operator, and all old code should work just fine. However, this may need to be fixed with existing QuestPDF-based libraries.

My suggestion is to simply update QuestPDF.Markdown, however, I am very open to discussion and risk assessment :)

christiaanderidder commented 7 months ago

Thanks for the bug report @danirzv. And thanks for the analysis @MarcinZiabek. It sounds like an easy fix, I will look into it.

MarcinZiabek commented 7 months ago

The QuestPDF 2024.3.0 is available only in the alpha version; you have around a month before this version becomes production-ready. If I am not mistaken, you only need to bump up the library version and rebuild your nuget. I am here to assist you in case any help is required :)

christiaanderidder commented 7 months ago

I've just released a pre-release version of QuestPDF.Markdown 1.8.0-alpha that targets QuestPDF 2024.3.0-alpha and makes use of the new Color struct. @danirzv please let me know if this version resolves the issue.

christiaanderidder commented 6 months ago

Closing due to inactivity, the provided solution should address the problem for now.