admin管理员组文章数量:1396763
Does there is any javascript code to convert generated google map into PDF using Javascript or any JS library?
Any help will be appreciated, and it will be more helpful if there is demo of such scenario.
Does there is any javascript code to convert generated google map into PDF using Javascript or any JS library?
Any help will be appreciated, and it will be more helpful if there is demo of such scenario.
Share Improve this question edited Mar 11, 2014 at 16:11 Kara 6,22616 gold badges53 silver badges58 bronze badges asked Mar 11, 2014 at 8:29 MazzuMazzu 2,84922 silver badges30 bronze badges 3- Have you seen this one Mazzu? stackoverflow./questions/2647833/google-maps-and-pdf This is a nice one as well: gis.stackexchange./questions/27510/… – Luis Gouveia Commented Mar 11, 2014 at 9:19
- 1 @LuisGouveia, yeah I have seen it but actually it doesn't relates – Mazzu Commented Mar 14, 2014 at 11:01
- 1 @LuisGouveia, can your provide any further details on it? – Mazzu Commented Mar 14, 2014 at 11:14
2 Answers
Reset to default 3I have a solution using 2 libraries: jspdf.min.js and html2canvas.js. add these to your index.html:
<script src="https://cdnjs.cloudflare./ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
function export_to_pdf() {
html2canvas(document.body, {
useCORS: true,
onrendered: function(canvas) {
var img =canvas.toDataURL("image/jpeg,1.0");
var pdf = new jsPDF();
pdf.addImage(img, 'JPEG', 15, 40, 180, 180);
pdf.save('a4.pdf')
}
});
}
explanation:
- html2canvas takes body or any other DOM element and creates a canvas object.
- canvas.toDataURL creates an image string.
- pdf.addImage adds the image to pdf object.
- pdf.save(), downloads the image.
If your okay with multiple libraries, you could try phantom.js to snapshot the html page then use node.js to convert to pdf.
本文标签: How to convert Google Map to PDF using JavascriptStack Overflow
版权声明:本文标题:How to convert Google Map to PDF using Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744129062a2592085.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论