Closed mjefim closed 1 month ago
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
uploaded pull request for this https://github.com/Relorer/HTMLToQPDF/pull/14
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?
create your own fork and merge my pr to your private branch/repo. or get use my fork directly. Sent from my iPhoneOn 14 May 2024, at 09:57, mjefim @.***> wrote:
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?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>
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:
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?