首页 > 解决方案 > 将 PDF 缓冲区转换为 PNG 缓冲区

问题描述

有没有办法将 PDF 缓冲区转换为 png 图像缓冲区?

我所能做的就是将pdf缓冲区转换为base 64,但我不知道下一步该做什么。

谢谢 !

标签: node.jspdfbufferpng

解决方案


我刚刚使用了https://github.com/yakovmeister/pdf2image,适用于我的用例,但需要一些本机 deps :

import { fromBuffer as convertPdfToPng } from 'pdf2pic'

const pdf2picOptions = {
  format: 'png',
  width: 2550,
  height: 3300,
  density: 330,
  savePath: './output/from-buffer-to-base64',
}

const convert = convertPdfToPng(pdfBuffer, pdf2picOptions)

const pageOutput = await convert(pageNumber, true)
const pngBuffer = Buffer.from(pageOutput.base64, 'base64')

推荐阅读