Reputation: 6764
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?
Upvotes: 8
Views: 16295
Reputation: 31
You can use this, this code place your image at middle of the line
let imageWidth = 180 // what you wants
doc.image('path/to/image.png',
doc.page.width/2 - imageWidth/2,doc.y,{
width:imageWidth
});
Upvotes: 3
Reputation: 159
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'
});
Upvotes: 15
Reputation: 6764
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 )
Upvotes: 21