It turns out that the javascript creating the chart wasn't getting a chance to create the chart and include it in the HTML before HiQPdf started converting it to the PDF.
I needed a way for HiQPdf to wait for the chart to be rendered before starting the conversion.
I found this demo in HiQ's documentation. It explains how you can manually trigger the conversion using javascript.
In the C# code:
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
htmlToPdfConverter.TriggerMode = ConversionTriggerMode.Manual;
(There are also 'Auto' and 'WaitTime' trigger modes)
And then on the webpage to trigger the conversion using javascript:
hiqPdfConverter.startConversion();
Awesome! so now all I needed was a way to call the startConversion() function when I knew the chart had finished rendering. Chart.js offers a few options to customize the chart animation process found here.
Among those options is an onComplete callback. So to pull it all together I added this to the Chart object:
options: {
animation: {
onComplete: function() {
hiqPdfConverter.startConversion();
}
},
...
}
Now the chart is fully rendered and part of the html that gets converted to the pdf via HiQPdf!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…