https://github.com/coderosh/images-to-pdf
Combine images to a single pdf. (browser and node)
https://github.com/coderosh/images-to-pdf
image-to-pdf image-to-pdf-converter pdf pdf-from-image
Last synced: 9 months ago
JSON representation
Combine images to a single pdf. (browser and node)
- Host: GitHub
- URL: https://github.com/coderosh/images-to-pdf
- Owner: coderosh
- License: mit
- Created: 2021-10-28T15:00:22.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-16T15:14:46.000Z (over 4 years ago)
- Last Synced: 2025-06-11T09:49:07.609Z (9 months ago)
- Topics: image-to-pdf, image-to-pdf-converter, pdf, pdf-from-image
- Language: TypeScript
- Homepage: https://coderosh.github.io/images-to-pdf
- Size: 87.9 KB
- Stars: 9
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# images-to-pdf
> Combine images to a single pdf. Works on both browser and node.
## Installation
```sh
# node
npm install @coderosh/images-to-pdf
# yarn
yarn add @coderosh/images-to-pdf
```
## Usage
This package requires image to be of type arraybuffer or uint8array.
- Using `imagesToPDF` function.
```js
import { imagesToPDF } from '@coderosh/images-to-pdf'
const main = async () => {
const img1 = await fetch('https://img1').then((res) => res.arrayBuffer())
const img2 = await fetch('https://img2').then((res) => res.arrayBuffer())
const pdf = await imagesToPDF([
img1,
{ src: img2, options: { height: 234, width: 345 } },
])
const dataUrl = pdf.dataUrl()
const arrayBuffer = pdf.arrayBuffer()
}
main()
```
- Using `ImagesToPDF` class.
```js
import ImagesToPDF from '@coderosh/images-to-pdf'
const main = async () => {
const img1 = await fetch('https://img1').then((res) => res.arrayBuffer())
const img2 = await fetch('https://img2').then((res) => res.arrayBuffer())
const img3 = await fetch('https://img3').then((res) => res.arrayBuffer())
const img4 = await fetch('https://img4').then((res) => res.arrayBuffer())
const imgToPdf = new ImagesToPDF([img1, { src: img2 }])
imgToPdf.addImage(img3)
imgToPdf.addImage(img4, { height: 234, width: 324 })
const pdf = await imgToPdf.createPdf()
const dataUrl = pdf.dataUrl()
const arrayBuffer = pdf.arrayBuffer()
}
main()
```
## License
MIT