【问题标题】:How to integrate google map into pdf using PDFKit如何使用 PDFKit 将谷歌地图集成到 pdf 中
【发布时间】:2020-10-07 11:46:34
【问题描述】:

我使用 nodejs 作为后端技术。我通过附加pdf发送电子邮件。我正在使用 pdfkit 生成 pdf (https://www.npmjs.com/package/pdfkit)。如何根据 pdf 中的坐标显示谷歌地图图像?

【问题讨论】:

    标签: node.js google-maps pdfkit node-pdfkit


    【解决方案1】:

    使用Google Maps Static 获取您的地图作为图像 获得地图图像后,您可以将其放入 PDF 中

    const PDFDocument = require('pdfkit');
    const axios = require('axios');
    
    const mapImg = `https://maps.googleapis.com/maps/api/staticmap?center=40.714%2c%20-73.998&zoom=12&size=400x400&key=${YOUR_API_KEY}`
    axios.get(mapImg, {
      responseType: 'arraybuffer'
    }).then((res) => {
      const doc = new PDFDocument;
      doc.image(res.data);
      doc.pipe(res);
      doc.end();
    })

    【讨论】:

      猜你喜欢
      • 2020-01-31
      • 1970-01-01
      • 2010-12-12
      • 1970-01-01
      • 2018-01-26
      • 2012-10-26
      • 2012-08-01
      • 2015-03-04
      • 1970-01-01
      相关资源
      最近更新 更多