Relorer / HTMLToQPDF

HTMLToQPDF is an extension for QuestPDF that allows to generate PDF from HTML
MIT License
80 stars 26 forks source link

System.MissingMethodException #17

Closed himadrinath closed 2 months ago

himadrinath commented 2 months ago

@Relorer tried this but getting exception

System.MissingMethodException
  HResult=0x80131513
  Message=Method not found: 'QuestPDF.Infrastructure.IContainer QuestPDF.Fluent.ElementExtensions.Element(QuestPDF.Infrastructure.IContainer, System.Func`2<QuestPDF.Infrastructure.IContainer,QuestPDF.Infrastructure.IContainer>)'.
  Source=HTMLToQPDF
  StackTrace:
   at HTMLQuestPDF.Components.Tags.ListComponent.ApplyStyles(IContainer container)
   at HTMLQuestPDF.Components.BaseHTMLComponent.Compose(IContainer container)
   at QuestPDF.Fluent.ComponentExtensions.Component[T](IContainer element, T component, Action`1 handler)
   at QuestPDF.Fluent.ComponentExtensions.Component[T](IContainer element, T component)
   at HTMLQuestPDF.Components.BaseHTMLComponent.<ComposeMany>b__6_0(ColumnDescriptor col)
   at QuestPDF.Fluent.ColumnExtensions.Column(IContainer element, Action`1 handler)
   at HTMLQuestPDF.Components.BaseHTMLComponent.ComposeMany(IContainer container)
   at HTMLQuestPDF.Components.BaseHTMLComponent.Compose(IContainer container)
   at QuestPDF.Fluent.ComponentExtensions.Component[T](IContainer element, T component, Action`1 handler)
   at QuestPDF.Fluent.ComponentExtensions.Component[T](IContainer element, T component)
   at HTMLQuestPDF.Components.BaseHTMLComponent.<ComposeMany>b__6_0(ColumnDescriptor col)
   at QuestPDF.Fluent.ColumnExtensions.Column(IContainer element, Action`1 handler)
   at HTMLQuestPDF.Components.BaseHTMLComponent.ComposeMany(IContainer container)
   at HTMLQuestPDF.Components.BaseHTMLComponent.Compose(IContainer container)
   at QuestPDF.Fluent.ComponentExtensions.Component[T](IContainer element, T component, Action`1 handler)
   at QuestPDF.Fluent.ComponentExtensions.Component[T](IContainer element, T component)
   at HTMLQuestPDF.Components.BaseHTMLComponent.<ComposeMany>b__6_0(ColumnDescriptor col)
   at QuestPDF.Fluent.ColumnExtensions.Column(IContainer element, Action`1 handler)
   at HTMLQuestPDF.Components.BaseHTMLComponent.ComposeMany(IContainer container)
   at HTMLQuestPDF.Components.BaseHTMLComponent.Compose(IContainer container)
   at QuestPDF.Fluent.ComponentExtensions.Component[T](IContainer element, T component, Action`1 handler)
   at QuestPDF.Fluent.ComponentExtensions.Component[T](IContainer element, T component)
   at HTMLToQPDF.Components.HTMLComponent.Compose(IContainer container)
   at QuestPDF.Fluent.ComponentExtensions.Component[T](IContainer element, T component, Action`1 handler)
   at QuestPDF.Fluent.ComponentExtensions.Component[T](IContainer element, T component)
   at HTMLQuestPDF.Extensions.HTMLComponentExtensions.HTML(IContainer container, Action`1 handler)
   at ReportDesigner.Program.<>c__DisplayClass0_2.<Main>b__17(ColumnDescriptor test_column) in C:\Users\ReportDesigner\Program.cs:line 275
   at QuestPDF.Fluent.ColumnExtensions.Column(IContainer element, Action`1 handler)
   at ReportDesigner.Program.<>c__DisplayClass0_0.<Main>b__4(ColumnDescriptor column) in C:\Users\ReportDesigner\Program.cs:line 199
   at QuestPDF.Fluent.ColumnExtensions.Column(IContainer element, Action`1 handler)
   at ReportDesigner.Program.<>c__DisplayClass0_0.<Main>b__1(PageDescriptor page) in C:\Users\ReportDesigner\Program.cs:line 193
   at QuestPDF.Fluent.PageExtensions.Page(IDocumentContainer document, Action`1 handler)
   at ReportDesigner.Program.<>c__DisplayClass0_0.<Main>b__0(IDocumentContainer container) in C:\Users\ReportDesigner\Program.cs:line 22
   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.GeneratePreviewerContent(IDocument document)
   at QuestPDF.Previewer.Extensions.<>c__DisplayClass1_0.<ShowInPreviewerAsync>g__GetPictures|4()
himadrinath commented 2 months ago

@JeremyVm can u help me with this

JeremyVm commented 2 months ago

@himadrinath We'll need a bit more information in regards to what you're trying to do?

Do you have a working code sample / repo so we can reproduce / test it?

himadrinath commented 2 months ago

@JeremyVm here is the example

internal class Program
{
    static void Main(string[] args)
    {
        QuestPDF.Settings.License = LicenseType.Community;
                string html = "<ol><li><p>Measurements in the same patient can show physiological &amp; analytical variations. Three serial samples 1 week apart are recommended for Total Cholesterol, Triglycerides, HDL &amp; LDL Cholesterol. </p></li><li><p>Lipid Association of India (LAI) recommends screening of all adults above the age of 20 years for Atherosclerotic Cardiovascular Disease (ASCVD) risk factors especially lipid profile. This should be done earlier if there is family history of premature heart disease, dyslipidemia, obesity or other risk factors</p></li></ol><h3>ASCVD Risk Stratification &amp; Treatment goals in Indian population</h3><ol><li><p>Indians are at very high risk of developing ASCVD, they usually get the disease at an early age, have a more severe form of the disease and have poorer outcome as compared to the western populations</p></li><li><p>Many individuals remain asymptomatic before they get heart attack, ASCVD risk helps to identify high risk individuals even when there is no symptom related to heart disease</p></li><li><p>ASCVD risk category helps clinician to decide when to consider therapy and what should be the treatment goal</p></li></ol><h3 style=\"text-align: center\"><mark>Treatment Goals as per Lipid Association of India 2020</mark></h3><table class=\"tiptap\" style=\"minWidth: 125px\"><colgroup><col><col><col><col><col></colgroup><tbody><tr><th colspan=\"1\" rowspan=\"2\"><p style=\"text-align: center\">ASCVD RISK&nbsp;</p><p style=\"text-align: center\">CATEGORY@</p></th><th colspan=\"2\" rowspan=\"1\"><p style=\"text-align: center\">CONSIDER THERAPY</p></th><th colspan=\"2\" rowspan=\"1\"><p style=\"text-align: center\">TREATMENT GOAL</p></th></tr><tr><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">LDL CHOLESTEROL</p><p style=\"text-align: center\">(LDL-C)(mg/dL)</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">NON HDL CHLOESTEROL</p><p style=\"text-align: center\">(NON HDL-C) (mg/dL)</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">LDL CHOLESTEROL</p><p style=\"text-align: center\">(LDL-C)(mg/dL)</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">NON HDL CHLOESTEROL</p><p style=\"text-align: center\">(NON HDL-C) (mg/dL)</p></td></tr><tr><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">Extreme (A)</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&gt;=50</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&gt;=80</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&lt;50 (Indispensable)</p><p style=\"text-align: center\">&lt;30 (Optional)</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&lt;80</p></td></tr><tr><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">Extreme (B)</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&gt;=30</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&gt;=60</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&lt;30</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&lt;60</p></td></tr><tr><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">Very High</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&gt;=50</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&gt;=80</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&lt;50</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&lt;80</p></td></tr><tr><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">High</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&gt;=70</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&gt;=100</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&lt;70</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&lt;100</p></td></tr><tr><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">Moderate</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&gt;=100</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&gt;=130</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&lt;100</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&lt;130</p></td></tr><tr><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">Low</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&gt;=130*</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&gt;=160*</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&lt;100</p></td><td colspan=\"1\" rowspan=\"1\" style=\"background-color: null\"><p style=\"text-align: center\">&lt;130</p></td></tr></tbody></table><p>* In low risk patient, consider therapy after an initial non-pharmacological intervention for at least 3 months</p><p></p><p><strong>@To know your risk category click on bit.ly link sent on your registered mobile number, answer the questionnaire, the ASCVD risk report can be downloaded from website.</strong></p>";

        var document = Document.Create(container =>
        {
            container.Page(page =>
            {
                page.Content().Column(col =>
                {
                    col.Item().HTML(handler =>
                    {
                        handler.SetHtml(html);
                    });
                });
            });
        });

        document.ShowInPreviewer();
    }
}

package reference

<PackageReference Include="QuestPDF" Version="2024.6.1" />
<PackageReference Include="QuestPDF.Barcodes" Version="2024.3.1" />
<PackageReference Include="QuestPDF.HTML" Version="1.0.0" />
MarcinZiabek commented 2 months ago

If I am not mistaken, this could be a breaking change introduced in the 2024.6.0 release. It extends the Element() method to collect context information about where it is invoked. That is further used to enhance the debugging experience in case of layout issues.

This change is invisible to a typical development workflow, as the compiler handles all attributes. However, it may require rebuilding the nuget library.

public static void Element(
    this IContainer parent, 
    Action<IContainer> handler,
    [CallerArgumentExpression("handler")] string handlerName = null, // <- invisible in IDE
    [CallerMemberName] string parentName = "",
    [CallerFilePath] string sourceFilePath = "",
    [CallerLineNumber] int sourceLineNumber = 0)

My suggestion is to rebuild the HTMLToQPDF library targeting QuestPDF 2024.6.X.

I am very sorry for this inconvenience. I strongly believe that this change is highly valuable to improve development experience now, and especially in the upcoming releases.

himadrinath commented 2 months ago

@MarcinZiabek @JeremyVm thanks you guys. it working just updated to 1.2.0

MarcinZiabek commented 2 months ago

@JeremyVm Thank you so much for the update and taking prompt action ❤️