I have a react component containing a map (using react-leaflet).
I am trying to take a screenshot of the map
(using html2canvas)
on the client side, convert it to HTML and then send it to my NodeJS server for creating a PDF (using html-pdf).
The problem is that the map loads its tiles from external URLs so when I try to take a screenshot I get a blank background.
Here is the component I want to take screenshot of:
React map component
Here is the result in PDF:
screenshot image
The code I've used:
on the client side:
// mapComponent is a div containing the component of the map.
let input = document.getElementById('mapComponent');
html2canvas(input)
.then((canvas) => {
let imgData = canvas.toDataURL('image/png');
sendAjaxRequest(imgData);
});
on the server:
let html = '<!DOCTYPE html><html><head></head><body><div>' +
'<img src="' + imgData + '">' +
'</div></body></html>';
let options = {
format: 'A4',
orientation: 'portrait'
};
pdf.create(html, options).toFile('./file.pdf', (err, res) => {
});
Help will be much appreciated.