Hi!
I’m using Aspose.Html and trying to convert html to pdf format.
Is it possible to execute js scripts?
my html (it’s not full, but there are only some more divs near existing one id=“air”):
<script src="https://www.google.com/jsapi"></script>
<script>
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
["", ""],
["Pending", 35],
["Approved", 50],
["Verified", 5],
["Closed", 2],
["Denied", 3],
["Canceled", 5],
]);
var options = {
is3D: false,
pieResidueSliceLabel: 'Остальное',
pieSliceText: 'none',
colors: [
"#4ed6dc",
"#13ac6c",
"#fdac34",
"#90a2d3",
"#f45279",
"#555d93",
],
pieStartAngle: 53,
chartArea: {
width: 250,
height: 130,
},
legend: {
alignment: 'center',
textStyle: {
fontName: 'Lato',
fontSize: 14,
}
},
};
var chart = new google.visualization.PieChart(document.getElementById('air'));
chart.draw(data, options);
}
</script>
<div id="air" class="chart"></div>
What about my C# code?
public async Task Generate(ReportGenerationModel model)
{
var htmlReport = await _htmlReportGenerationService.Generate(model);
var styles = _reportStylesRetriever.Retrieve(model.ReportType);
var options = new PdfSaveOptions();
using var memoryStreamProvider = new MemoryStreamProvider();
using var configuration = new Configuration();
var userAgent = configuration.GetService<Aspose.Html.Services.IUserAgentService>();
userAgent.UserStyleSheet = styles;
using var document = new HTMLDocument(htmlReport, ".", configuration);
Converter.ConvertHTML(document, options, "example.pdf");
}
I’m pretty sure that it works correctly because of I successfully genereted pdf, and all info was there, but not this piechart (div with id="air). If you will try to move this code to any renderer, you will see that it works correctly.
So, Is there way to render scripts? If it possible, I would be so gratefull if you will describe it. Thank you!