Skip to content

Latest commit

 

History

History
71 lines (49 loc) · 1.99 KB

README.md

File metadata and controls

71 lines (49 loc) · 1.99 KB

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