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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744129070a4559746.html
评论列表(0条)