Convert a specific page of a PDF into an image (PNG or base64) using a simple Node.js wrapper over Python. Supports S3 URLs and PDF buffers.
npm install pdfpage-to-imageConvert a specific page of a PDF into an image (PNG or base64) using a simple Node.js wrapper over Python. Supports S3 URLs and PDF buffers.
---
``bash`
npm install pdfpage-to-image
bash
In Dockerfile:
RUN apt-get update && \
apt-get install -y python3 python3-pip poppler-utils && \
pip3 install pdf2image requests
`š Usage
`bash
š§ Import and Use
const pdfToImage = require('pdfpage-to-image');Examples -
š¦ PDF buffer Option
const base64Data = await pdfToImage.convertPDFPage({
buffer: pdfBytes, // ArrayBuffer or Buffer of the PDF
page: 2, // Page number
output: 'base64' // 'base64' or 'png'
});
š¦ S3 URL Option
const base64Data = await pdfToImage.convertPDFPage({
s3Url: 'https://example.com/sample.pdf',
page: 1,
output: 'base64'
});
`
š ļø API
`bash
convertPDFPage(options: send either s3Url or buffer only)
s3Url: string
buffer: Buffer
page: number
output: 'base64' | 'png'
`š¤ Output
`bash
Returns an object:
{
type: 'base64',
data: ''
}
Or if output: 'png' is selected:
{
type: 'png',
path: '/tmp/output1234.png' // Path to PNG file
}
`šØāš» Author
`bash
Mohd Zaid Multani
Feel free to contribute, open issues, or reach out!
``---
Let me know if you want a TypeScript usage section or if you're planning to add support for multiple pages or output formats ā I can help update it accordingly!