For a project I'm working on, I've integrated jspdf to convert some charts into a PDF. The framework I'm using is angularjs 1.5.6, and the charts are created with chart.js. The HTML snippet for the charts looks like this:
<div name="charts" class="charts">
<div class="ft" style="width:45%; height:550px; margin-top: 20px;margin-left:2%;">
<canvas id="biChart" class="chart chart-bar" chart-data="biData" chart-labels="biLabels" chart-options="biOptions" chart-series="series" chart-colors="biColors" chart-dataset-override="biDatasetOverride"></canvas>
</div>
<div class="fr" style="width:45%; height:550px; margin-top: 20px;margin-right:2%;">
<canvas id="qzsChart" class="chart chart-bar" chart-data="qzsData" chart-labels="qzsLabels" chart-options="qzsOptions" chart-series="series" chart-colors="qzsColors" chart-dataset-override="qzsDatasetOverride"></canvas>
</div>
</div>
The function used to export the charts to PDF is as follows:
$scope.exportChart = function() {
var biChart = document.getElementById("biChart");
var qzsChart = document.getElementById("qzsChart");
var doc = new jsPDF('p', 'mm');
var text = "Sample Charts";
var xOffset = (doc.internal.pageSize.width / 2) - (doc.getStringUnitWidth(text) * doc.internal.getFontSize() / 2);
doc.text(text, xOffset, 10);
doc.addImage(biChart.toDataURL('image/png'), 'PNG', 10, 10);
doc.addPage();
doc.addImage(qzsChart.toDataURL('image/png'), 'PNG', 10, 10);
doc.save('sample-chart.pdf');
}
After generating the PDF, I can view it in the browser without any issues. However, when attempting to open the file using Adobe Reader, an error message is displayed:
https://i.sstatic.net/OwDkp.jpg
Could there be a problem with my code implementation?