Js Remote Jpeg to Pdf
installation
- sharp
- image-to-pdf
- image-size
import sharp from 'sharp'
import imgToPDF from "image-to-pdf"
import imageSize from "image-size"
const imagePath = './1.jpg'
const pdfPath = './1.pdf'
const imageBuffer = await (await request.get(url)).body()
const jpgBuffer = await sharp(imageBuffer).jpeg({ mozjpeg: true }).toBuffer()
fs.writeFileSync(imagePath, jpgBuffer)
const size = imageSize(imagePath)
const images = [imagePath]
imgToPDF(images, [size.width, size.height]).pipe(
fs.createWriteStream(pdfPath)
);