Closed habibr closed 5 years ago
Hi there.
How do you think this should work? Do your client have any other page formats on his printer?
Regards, Igor
No, sorry, I mean not printing on printer. I should rephrase my question: I need to save image of the map with sizes and orientation following the client's screen.
There is a way, but some adjustments needed. Please wait couple of days to be updated.
Best way for now for you is to use something like next:
L.control.browserPrint.mode("Auto", "Export image", "EI", function(context) { return function() { // hide print control from curent map var control = document.querySelector(".leaflet-control-browser-print"); control.style.visibility = "hidden"; // actula export image logic; setTimeout(function(){ domtoimage .toPng(document.querySelector("#map"), { height: map._container.clientHeight, width: map._container.clientWidth }) // query actual print map container, or any other needed container to print .then(function (dataUrl) { var link = document.createElement('a'); link.download = map.printControl.options.documentTitle || "exportedMap" + '.png'; link.href = dataUrl; link.click(); control.style.visibility = ""; }); }, 1); }}, false),
It's additional printMode that you can use to export map as it is. Just play with a sizes.
Thank you Igor, that code worked very well for my purpose.
I need to print the map not as defined A or B sizes. Rather, the print should follow the size of the displayed map in the client's screen. Is it possible to do so?