Convert PDF files into images using Poppler with promises. Core wrapper package without binaries. Requires a platform-specific binary package.
npm install pdf-poppler-corebash
npm install pdf-poppler-core pdf-poppler-binaries-linux
`
$3
If you need to fill PDF forms (with libraries like pdf-lib) and convert them to images, use the fonts package:
`bash
npm install pdf-poppler-core pdf-poppler-binaries-linux-fonts
`
This package bundles Liberation Sans fonts and fontconfig, ensuring form field text renders correctly in environments without system fonts.
$3
`bash
npm install pdf-poppler-core pdf-poppler-binaries-win32
`
$3
`bash
npm install pdf-poppler-core pdf-poppler-binaries-darwin
`
$3
`bash
Install Linux binaries for production
npm install pdf-poppler-core pdf-poppler-binaries-linux
Install Windows binaries for local development
npm install --save-dev pdf-poppler-binaries-win32
`
Both packages will be available during development, but only the Linux binaries will be deployed to production.
Usage
$3
`javascript
const { PdfPoppler } = require('pdf-poppler-core');
// Create an instance (auto-detects platform)
const poppler = new PdfPoppler();
// Get PDF info
const info = await poppler.info('/path/to/file.pdf');
console.log(info.pages, info.page_size);
// Convert PDF to images
await poppler.convert('/path/to/file.pdf', {
format: 'png',
out_dir: '/output/directory',
out_prefix: 'page',
scale: 1024
});
// Get embedded image data
const images = await poppler.imgdata('/path/to/file.pdf');
`
$3
`javascript
const { PdfPoppler } = require('pdf-poppler-core');
// For AWS Lambda (auto-configures xvfb and Lambda settings)
const lambdaPoppler = PdfPoppler.forLambda();
// For CI environments
const ciPoppler = PdfPoppler.forCI();
// With custom binary path
const customPoppler = PdfPoppler.withBinaryPath('/custom/poppler/bin');
// Auto-detect everything
const autoPoppler = PdfPoppler.autoDetect();
`
$3
`javascript
const { PdfPoppler } = require('pdf-poppler-core');
const config = PdfPoppler.configure()
.withOsBinary() // Use auto-detected OS binaries
.withPreferXvfb(false) // Disable xvfb preference
.withVersion('24.02') // Use specific version
.withMaxBuffer(10 1024 1024) // Set max buffer
.build();
const poppler = new PdfPoppler(config);
`
$3
`javascript
const { PdfPoppler } = require('pdf-poppler-core');
const poppler = new PdfPoppler({
binaryPath: '/custom/path/to/bin', // Optional: explicit binary path
preferXvfb: true, // Optional: prefer xvfb variant
version: '24.02', // Optional: specific version
isLambda: true, // Optional: force Lambda mode
isCI: false, // Optional: force CI mode
execOptions: {
maxBuffer: 10 1024 1024, // Optional: buffer size
timeout: 30000 // Optional: timeout in ms
}
});
`
$3
`javascript
const poppler = new PdfPoppler();
// Get PDF metadata
const info = await poppler.info('/path/to/file.pdf');
// Convert PDF to images
await poppler.convert('/path/to/file.pdf', {
format: 'png', // 'png' | 'jpeg' | 'tiff' | 'pdf' | 'ps' | 'eps' | 'svg'
out_dir: './output', // Output directory
out_prefix: 'page', // Output filename prefix
page: 1, // Specific page (null for all pages)
scale: 1024 // Scale (only for png, jpeg, tiff)
});
// Get embedded image data
const images = await poppler.imgdata('/path/to/file.pdf');
// Utility methods
poppler.getPath(); // Get binary path
poppler.getVersion(); // Get detected version
poppler.getAvailableVersions(); // Get all available versions
poppler.isLambdaEnvironment(); // Check if Lambda mode
poppler.hasBundledXvfb(); // Check if using xvfb
poppler.getConfig(); // Get resolved configuration
poppler.getExecOptions(); // Get execution options
`
$3
This package is written in TypeScript and includes type definitions.
`typescript
import { PdfPoppler, PdfInfo, ConvertOptions } from 'pdf-poppler-core';
const poppler = new PdfPoppler();
const info: PdfInfo = await poppler.info('./document.pdf');
console.log(info.pages, info.width_in_pts, info.height_in_pts);
const options: ConvertOptions = {
format: 'png',
out_dir: './output',
scale: 800
};
await poppler.convert('./document.pdf', options);
`
Environment Variables
The following environment variables can configure behavior:
| Variable | Description |
|----------|-------------|
| POPPLER_BINARY_PATH | Direct path to poppler bin directory |
| POPPLER_BINARY_PACKAGE | Custom npm package for binaries |
| POPPLER_VERSION | Preferred poppler version |
| POPPLER_PREFER_XVFB | Set to 'false' to disable xvfb |
Platform Support
- Linux (x64) - Including AWS Lambda
- Windows (x64)
- macOS (x64)
- Other platforms - Supported via custom binary configuration
AWS Lambda Support
This package works in AWS Lambda environments. Use the forLambda() factory method for optimal configuration:
`javascript
const { PdfPoppler } = require('pdf-poppler-core');
const poppler = PdfPoppler.forLambda();
exports.handler = async (event) => {
const info = await poppler.info('/tmp/document.pdf');
await poppler.convert('/tmp/document.pdf', {
format: 'png',
out_dir: '/tmp',
out_prefix: 'page'
});
return { statusCode: 200 };
};
``