An open API service indexing awesome lists of open source software.

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)

Awesome Lists containing this project

README

          

# images-to-pdf

> Combine images to a single pdf. Works on both browser and node.

NPM
MIT
CI
PRs welcome!

## 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