Converting Canvas to PDF with Custom DPI using chart.js and html2pdf.js
If you want to adjust the output resolution for the canvas in the PDF, you'll need to set the DIP value.
Assuming an A4 size is approximately 11+ inches across in landscape mode and you intend to fit 2000 pixels, adding a margin total of 1+ inch would make the width of the graph 10". Using CSS unit points (72 points per inch), the canvas size should be 720pt across. Adjust the height proportionally.
To calculate the DPI, divide the canvas.width by the size: 2000 / 10 = 200.
If you prefer a higher DPI, a more accurate approach can be taken as shown below:
const A4 = {
width : 11.69,
height : 8.27,
}
const points = 72;
const graphWidth = 10;
const graphDPI = 300;
// Rest of the code for generating the PDF goes here