node.jspdfpdfkitnode-pdfkit

PDFKit - locate image in center


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?


Solution

  • I've found an indirect way to solve the problem - simply calculate the center and locate the picture there:

     doc.image('images/test.jpeg', (doc.page.width - imageWidth) /2 )