How to convert Google Map to PDF using Javascript? - Stack Overflow

Does there is any javascript code to convert generated google map into PDF using Javascript or any JS l

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
Add a ment  | 

2 Answers 2

Reset to default 3

I 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:

  1. html2canvas takes body or any other DOM element and creates a canvas object.
  2. canvas.toDataURL creates an image string.
  3. pdf.addImage adds the image to pdf object.
  4. 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

相关推荐

  • How to convert Google Map to PDF using Javascript? - Stack Overflow

    Does there is any javascript code to convert generated google map into PDF using Javascript or any JS l

    9天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信