PDFKit - locate image in center

griffon vulture picture griffon vulture · Oct 22, 2014 · Viewed 9.3k times · Source

Using PDFKit on node.js:

 var PDFDocument = require('pdfkit')
 var doc = new PDFDocument()
 doc.image('images/test.jpeg')

How can I centerize an image added to the PDF?

Is it optional to do it using PDFKit or do I need to use another library?

Answer

Ibrahim Zahoor picture Ibrahim Zahoor · Feb 22, 2017

Using PDFKit on node.js: We can center the image using following code

doc.image('path/to/image.png', {
  fit: [250, 300],
  align: 'center',
  valign: 'center'
});