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?
Source Code PDFKit A JavaScript PDF generation library for Node and the browser. Description PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable documents easy.
This can cause issues of Images not appearing in your generated PDF documents if they are not stored locally on the server. Manually insert into HTML template. Our front end is uploading images and sending them to our RAILS API to generate the HTML document
Distributed as pdfkit.standalone.jsfile in the releasesor in the package jsfolder. In addition to PDFKit, you'll need somewhere to stream the output to. HTML5 has a Blobobject which can be used to store binary data, and get URLs to this data in order to display PDF output inside an iframe, or upload to a server, etc.
HTML5 has a Blobobject which can be used to store binary data, and get URLs to this data in order to display PDF output inside an iframe, or upload to a server, etc. In order to get a Blob from the output of PDFKit, you can use the blob-streammodule.
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 )
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'
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With