pdfpage-to-image
v1.0.10
Published
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.
Readme
📄 pdfpage-to-image
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.
🚀 Installation
npm install pdfpage-to-image🔧 System Requirements
This package requires Python and Poppler to be installed. Install them in your Dockerfile or system manually.
📦 Dependencies
Python 3.x poppler-utils Python packages: pdf2image requests
🐳 Docker Setup (example)
In Dockerfile:
RUN apt-get update && \
apt-get install -y python3 python3-pip poppler-utils && \
pip3 install pdf2image requests📘 Usage
🧠 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
convertPDFPage(options: send either s3Url or buffer only)
s3Url: string
buffer: Buffer
page: number
output: 'base64' | 'png' 📤 Output
Returns an object:
{
type: 'base64',
data: '<base64 string>'
}
Or if output: 'png' is selected:
{
type: 'png',
path: '/tmp/output1234.png' // Path to PNG file
}👨💻 Author
Mohd Zaid Multani
Feel free to contribute, open issues, or reach out!📄 License
MIT
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!
