Kevin S
Kevin S

Reputation: 172

Making a "screenshot" of the current website using HTML or JavaScript?

I have tried html2canvas, but did not work as expected, because I am using Google Maps with custom markers and when it will just make a screenshot of the map without these markers.

I want to make a screenshot so that it looks like:

enter image description here

But the result is:

enter image description here

The chart does also not look that great. Are there any alternatives I can use?

Here is the code I used to create an image using html2canvas (where #downloadPDF is a button):

<script type="text/javascript">
jQuery(document).ready(function ($) {
    $('#downloadPDF').click(function () {
        html2canvas($(".map"), {
            logging: true,
            useCORS: true,
            onrendered: function (canvas) {
                var imgData = canvas.toDataURL('image/png');
                window.open(imgData);
            }
        });
    });
});

Upvotes: 5

Views: 582

Answers (1)

Luke P
Luke P

Reputation: 734

Not sure on your hosting setup, but I have used PhantomJS to create screenshots of web pages, and save them as images or PDFs.

When you download the library, there is a rasterize.js in the example directory which allows you to pass in arguments to save a URL. You could modify this so that it pauses for a few seconds, then saves the page - giving the map enough time to load properly.

http://phantomjs.org

Upvotes: 1

Related Questions