image-to-pdf
v2.0.0
Published
A simple image to PDF converter
Downloads
7,479
Readme
Welcome to image-to-pdf 👋
A simple 🖼️ to 📄 converter for NodeJS
Instalation
npm install image-to-pdf
# OR
yarn add image-to-pdf
Example
const imgToPDF = require('image-to-pdf')
const fs = require('fs')
const pages = [
"./pages/image1.jpeg", // path to the image
"data:image/png;base64,iVBORw...", // base64
fs.readFileSync('./pages/image3.png') // Buffer
]
imgToPDF(pages, imgToPDF.sizes.A4)
.pipe(fs.createWriteStream('output.pdf'))
Documentation
Accepted formats
The only accepted image formats are png
and jpeg
. They can be passed to the function as base64
, Buffer
or simply as a path to the file (see Example).
Page size
A list of all size presets in imgToPDF.sizes
can be found here. A custom size can be passed to the function simply as [x, y]
.
Output
The function returns a Stream
(see official documentation). The easiest way to get a file is to pipe
it into a WriteStream
(see Example).