A utility for converting pdf to image and base64 format.
- node >= 8.x
- graphicsmagick
- ghostscript
- converts pdf to image.
- converts pdf to base64.
- customizable output.
- customizable image quality.
- fs-extra
- gm
- gm-base64
npm install -S pdf2pic
const PDF2Pic = require("pdf2pic");
const pdf2pic = new PDF2Pic({
density: 100, // output pixels per inch
savename: "untitled", // output file name
savedir: "./images", // output file location
format: "png", // output file format
size: "600x600" // output size in pixels
});
pdf2pic.convert("/path/to/pdf/sample.pdf").then((resolve) => {
console.log("image converter successfully!");
return resolve;
});
const PDF2Pic = require("pdf2pic");
const pdf2pic = new PDF2Pic({
density: 100, // output pixels per inch
savename: "untitled", // output file name
savedir: "./images", // output file location
format: "png", // output file format
size: "600x600" // output size in pixels
});
pdf2pic.convertBulk("path/to/pdf/sample.pdf", -1).then((resolve) => {
console.log("image converter successfully!");
return resolve;
});
const PDF2Pic = require("pdf2pic");
const pdf2pic = new PDF2Pic({
density: 100, // output pixels per inch
savename: "untitled", // output file name
savedir: "./images", // output file location
format: "png", // output file format
size: "600x600" // output size in pixels
});
pdf2pic.convertBulk("path/to/pdf/sample.pdf", [1,4,6]).then((resolve) => {
console.log("image converter successfully!");
return resolve;
});
const PDF2Pic = require("pdf2pic");
const pdf2pic = new PDF2Pic({
density: 100, // output pixels per inch
savename: "untitled", // output file name
savedir: "./images", // output file location
format: "png", // output file format
size: "600x600" // output size in pixels
});
pdf2pic.convertToBase64("path/to/pdf/sample.pdf").then((resolve) => {
if (resolve.base64) {
console.log("image converter successfully!");
// assuming you're using some ORM to save base64 to db
return db.model.table('users').update({id: "1", image: resolve.base64});
}
});