[英]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. 我已经尝试了html2canvas,但没有按预期工作,因为我使用带有自定义标记的谷歌地图,当它只是制作没有这些标记的地图的截图。
I want to make a screenshot so that it looks like: 我想做一个截图,看起来像:
But the result is: 但结果是:
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): 这是我用来使用html2canvas创建图像的代码(其中#downloadPDF是一个按钮):
<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);
}
});
});
});
Not sure on your hosting setup, but I have used PhantomJS to create screenshots of web pages, and save them as images or PDFs. 不确定您的主机设置,但我使用PhantomJS创建网页的屏幕截图,并将其保存为图像或PDF。
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. 下载库时,示例目录中有一个rasterize.js,它允许您传入参数以保存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. 您可以修改它以使其暂停几秒钟,然后保存页面 - 为地图提供足够的时间来正确加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.