@coderosh/images-to-pdf
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

images-to-pdf

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

NPM MIT CI PRs welcome!

Installation

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

    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.

    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

Package Sidebar

Install

npm i @coderosh/images-to-pdf

Weekly Downloads

129

Version

2.1.0

License

MIT

Unpacked Size

8.26 kB

Total Files

9

Last publish

Collaborators

  • coderosh