node.js - 如何使用 PDFKit 将谷歌地图集成到 pdf 中
问题描述
我使用 nodejs 作为后端技术。我通过附加pdf发送电子邮件。我正在使用 pdfkit 生成 pdf ( https://www.npmjs.com/package/pdfkit )。如何根据 pdf 中的坐标显示谷歌地图图像?
解决方案
获得地图图像后,使用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();
})
推荐阅读
- firefox-addon - Firefox插件直接从标签打印/下载到特定位置
- android - Deeplink ionic3:不要在安卓上启动应用
- node.js - 如何仅在更新字段时触发 Firebase 云功能?
- r - R - Shiny 不会让我转换序列日期
- python-2.7 - Matplotlib:内存和“CPU”泄漏
- javascript - ng-if中的Angular JS多重条件
- office365 - Sharepoint online - API 中缺少 DlpSensitiveTypes?
- python - 对数据框列执行 JSON 操作
- rspec - 如何在 RSPEC 中设置语言环境
- python - 使用逻辑填充缺失数据 Pandas