Search code examples
reactjspdf-generationreact-leaflet

React Leaflet map to PDF


I can generate PNG file by using

https://www.npmjs.com/package/react-leaflet-easyprint

I need to generate PDF from PNG file.

How can I prevent download of the file and use this content to generate PDF file before download PNG file?

Is there maybe better library for this purpose?

There is also an option to use nodeJs and phantomJs, but in this case there will be code duplication.


Solution

  • The leaflet-easyprint library leverages the dom-to-image library.

    https://github.com/rowanwins/leaflet-easyPrint/blob/gh-pages/src/index.js#L127

    I suggest copying a bit of the code from there and using dom-to-image + filesaver to convert the dom to a base64 blob export as a pdf.

    https://github.com/tsayen/dom-to-image#usage