0

Thanks in advance..

I am creating a pdf from html using iText7 and in that html I am creating a chart on canvas with chart.js. All these are in memory in c# service where I can not use Chrome or any browser library with selenium.

I want to generate chart on canvas with dynamic data in html string. I have tried Jint but not able to succeed. Below is what I have tried -

// Parse HTML
var parser = new HtmlParser();
var document = parser.ParseDocument(htmlStr);
// Get all <script> tags
var scriptTags = document.QuerySelectorAll("script");
// Execute JavaScript in each <script> tag
//var engine = new Engine()
var engine = new Engine(options => options.AllowClr());
engine.Execute(File.ReadAllText("charthtml/js/chart.min.js"));
engine.SetValue("document", document);

foreach (var scriptTag in scriptTags)
{
    var scriptCode = scriptTag.InnerHtml;
    var result = engine.Evaluate(scriptCode, htmlStr);
    if (result.Type == Types.Object)
    {
        scriptTag.InnerHtml = result.ToString();
    }
}

// Return modified HTML
replacedevaluatedHtml = document.DocumentElement.OuterHtml;

Please guide me here. I am thinking that using JINT, I am not able to generate chart on html5 canvas element (correct me if I am wrong). I am open to use any other open source

Sachin
  • 2,152
  • 1
  • 21
  • 43
  • 1
    I think jint is a JS interpreter. That doest mean it renders HTML so maybe you need to arrange a webview on the c# side. Once you achieve that, you can make c# and JS interop with jint – rustyBucketBay Aug 12 '23 at 11:22

0 Answers0