pdf-images
v1.3.3
Published
The pf-images library aims to simplify pdf-conversion by using poppler / pdfImages & imageMagick to convert pdfs to images.
Downloads
538
Maintainers
Readme
Note
Usage: Poppler
const { Poppler } = require('pdf-images');
const result = Poppler.convert('/pdf/path/sample_pdf.pdf', 'output/directory/path', 'outputName'); // you can also add a 4th arguement which can specify the output image extension like jpg or jpeg
- A successfull result will look something like:
{
pdfPath: '/pdf/path/sample_pdf.pf',
outputImagesDirectory: '/output/directory/outputName/',
images: [
'/output/directory/outputName/outputName-001.png',
'/output/directory/outputName/outputName-002.png'
],
success: true
}
- An error response will look something like:
{
pdfPath: '/pdf/path/sample_pdf.pf',
error: <Err object>
}
Usage: ImageMagick
Async api to convert
- By default images have png extension
- you can also add a string of the args that you want to run with the imagemagick shell command. checkout
resultWithArgs
const { ImageMagick } = require('pdf-images');
const result = ImageMagick.convertAsync('/pdf/path/sample_pdf.pdf', 'output/directory/path', 'outputName');
const resultWithArgs = ImageMagick.convertAsync('/pdf/path/sample_pdf.pdf', 'output/directory/path', 'outputName', '-alpha background');
const resultWithDifferentExtension = ImageMagick.convertAsync(
'/pdf/path/sample_pdf.pdf',
'output/directory/path',
'outputName',
null,
'jpeg',
);
- A successfull result will look something like:
{
pdfPath: '/pdf/path/sample_pdf.pf',
outputImagesDirectory: '/output/directory/outputName/',
commandExecuted: 'convert -quiet -alpha background -density 200 -quality 100 /pdf/path/sample_pdf.pf /output/directory/outputName/outputName.jpeg',
images: [
'/output/directory/outputName/outputName-001.jpeg',
'/output/directory/outputName/outputName-002.jpeg'
],
success: true
}
const { ImageMagick } = require('pdf-images');
const result = ImageMagick.convert('/pdf/path/sample_pdf.pdf', 'output/directory/path', 'outputName'); // you can also add a 4th arguement which can specify the output image extension like jpg or jpeg
- A successfull result will look something like:
{
pdfPath: '/pdf/path/sample_pdf.pf',
outputImagesDirectory: '/output/directory/outputName/',
images: [
'/output/directory/outputName/outputName-001.png',
'/output/directory/outputName/outputName-002.png'
],
success: true
}
- An error response will look something like:
{
pdfPath: '/pdf/path/sample_pdf.pf',
error: <Err object>
}
- To set the density and quality of imagemagick use:
ImageMagick.setQuality(100);
ImageMagick.setDensity(200);
- Default ImageMagick quality is 100 and density is 200