My .Net Web API needs to read one input HTML file with some Javascript contents for Charts/SVG rendering on a browser which needs to be converted to PDF further with the help of some third-party conversion tool using their APIs. But the conversion tool does not fully support JavaScript/Dynamic Contents rendering directly so We Are Trying to Use PhantomJS to make the output Supportable with that tool. But facing issues in implementing PhantomJS for the same. Can anyone help in resolving the issue with Sample Code??
Scenario: We have one HTML file which contains some JavaScript code inside it/external source. We need to get the contents of the HTML file in form of string using C# code.
We are trying it in the following way(using NReco.PhantomJS):
public string Conversion()
{
string script ="var page = require('webpage').create();" +
"var url = 'Local_File_Path/fileName.html';" +
"page.open(url, function(status) {" +
"if (status !== 'success'){" +
"console.log('Unable to load the address!');" +
"phantom.exit();" +
"}else{"+
"window.setTimeout(function() {"+
"page.render(MyJavaScriptFuntion);"+
"phantom.exit();"+
"}, 1000);"+
"console.log(status);" +
"phantom.exit();"+
")};";
string output = string.Empty;
var phantomJS = new PhantomJS();
phantomJS.OutputReceived += (sender, e) =>
{
output += e.Data;
};
phantomJS.RunScript(script, null);
return output;
}
I Have already looked into the below Links but I'm unable to Implement Successfully.
And many others.
(Actually, I'm not sure how to utilize the given solutions in my problem. ) Thanks in Advance.