How to integrate google map into pdf using PDFKit

345 views Asked by At

I'm using nodejs as backend technology. I'm sending a email by attaching a pdf. I'm using to pdfkit to generate pdf (https://www.npmjs.com/package/pdfkit ). How can i display google map image according to the coordinates in the pdf ?

1

There are 1 answers

0
Ittiunited On

Get your map as Image by using Google Maps Static once you have the map image you can place it in your 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();
})