Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when <ul> present in the HTML #12

Open
mjefim opened this issue Jan 8, 2024 · 4 comments
Open

Exception when <ul> present in the HTML #12

mjefim opened this issue Jan 8, 2024 · 4 comments

Comments

@mjefim
Copy link

mjefim commented Jan 8, 2024

I am receiving an exception while trying to render an <ul> list.

The exeption:
Method not found: 'QuestPDF.Infrastructure.IContainer QuestPDF.Fluent.ElementExtensions.Element(!!0, System.Func`2<QuestPDF.Infrastructure.IContainer,QuestPDF.Infrastructure.IContainer>)'.

Example content:

<p>A paragraph</p>
<ul>
	<li>First item in the list</li>
</ul>

If I omit the <ul> tag the PDF is generated successfully. I also tried the same content with the HTMLToQPDF.Example.exe downloaded from the project page and it works. Is there something I am missing?

@jbennie
Copy link

jbennie commented Feb 16, 2024

I second this. versions : .net runtime 8.0.2, QuestPDF 2023.12.5 , HTMLToQPDF 1.1.0
example of html component , tried as Dynamic and as standard component - same result.

/// start of code

using HtmlAgilityPack;
using HTMLQuestPDF.Extensions;
using QuestPDF.Elements;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
using SedgemanWebGQLAPI.Models.Reporting;
using System;


namespace SedgemanWebGQLAPI.Controllers.QuestControllers.Components
{
    public class CssHtml : IDynamicComponent
    {
        
        public VLetter _letter { get; set; }
     
        public CssHtml(VLetter page) { 

            this._letter = page;
        }

        public static byte[] MyGetImgBySrc(string src)
            {

            
                try
                {
                    if (src.Contains("base64"))
                    {
                        var base64 = src.Substring(src.IndexOf("base64,") + "base64,".Length);
                        return Convert.FromBase64String(base64);
                    }
                    
                
                    Uri _Img = new Uri(src); 
                    
                  return  CssWebWorker.Client.DownloadAsBytes(_Img).Result;
                   
                }
                catch
                {
                    return null;
                }
            }

        public  void RemoveStyleAttributes( HtmlDocument html)
        {
            var elementsWithStyleAttribute = html.DocumentNode.SelectNodes("//@style");

            if (elementsWithStyleAttribute != null)
            {
                foreach (var element in elementsWithStyleAttribute)
                {
                    element.Attributes["style"].Remove();
                }
            }
        }


        public DynamicComponentComposeResult Compose(DynamicContext context)
        {
            var content = context.CreateElement(el =>
            {
                el.Column( col => {

                    col.Item().Text(t => t.EmptyLine());
                    col.Item().HTML(handler => {

                    var htmlDoc = new HtmlDocument();

                
                    string filebody =  _letter.Body ;
   
                    htmlDoc.OptionFixNestedTags = true;
                    htmlDoc.OptionWriteEmptyNodes = false; // Write self-closing tags if necessary

                    htmlDoc.LoadHtml(filebody.Replace("\n",String.Empty ).Replace("\t", string.Empty).Replace("\r",string.Empty));
                 
                    RemoveStyleAttributes(htmlDoc);


                    string cleanedHtml = htmlDoc.DocumentNode.OuterHtml;

                        handler.OverloadImgReceivingFunc(MyGetImgBySrc);

                        handler.SetContainerStyleForHtmlElement("p", c => c.AlignLeft());

                        handler.SetContainerStyleForHtmlElement("ul", c => c.PaddingVertical(10));

                        handler.SetContainerStyleForHtmlElement("li", c => c.PaddingLeft(10));

                        handler.SetHtml(cleanedHtml);
                });

                });
            });

            return new DynamicComponentComposeResult()
            {
                Content = content,
                HasMoreContent = false
            };
        }
    }
}

// end of code

// start of data in letter.body

<p>some text</p>
<p></p>
<ul><li> some text </li> </ul>

// end data in

@jbennie
Copy link

jbennie commented Feb 16, 2024

uploaded pull request for this #14

@mjefim
Copy link
Author

mjefim commented May 14, 2024

uploaded pull request for this #14

Is there a way to get your fixed version? The pull request has not been accepted nor has a new release been created, can I side-step this?

@jbennie
Copy link

jbennie commented May 14, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants