Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
A utility for converting pdf to image and base64 format.
IMPORTANT NOTE: Please support this library by donating via PayPal, your help is much appreciated. Contributors are also welcome!
ANOTHER IMPORTANT NOTE: please use version 1.x for now as 2.x is still in early development stage
Follow this guide to install the required dependencies.
npm install -S pdf2pic
import { fromPath } from "pdf2pic";
const options = {
density: 100,
savename: "untitled",
savedir: "./images",
format: "png",
width: 600,
height: 600
};
const storeAsImage = fromPath("/path/to/pdf/sample.pdf", options);
const pageToConvertAsImage = 1;
storeAsImage(pageToConvertAsImage).then((resolve) => {
console.log("Page 1 is now converted as image");
return resolve;
});
import { fromPath } from "pdf2pic";
const options = {
density: 100,
savename: "untitled",
savedir: "./images",
format: "png",
size: "600x600"
};
const convertPdf2Base64Image = fromPath("/path/to/pdf/sample.pdf", options);
const pageToConvertAsImage = 1;
// adding true as second parameter will transform response to base64 string
convertPdf2Base64Image(pageToConvertAsImage, true).then((resolve) => {
console.log("Page 1 is now converted as base64string");
console.log({
base64string: resolve.base64
})
return resolve;
});
import { fromPath } from "pdf2pic";
const options = {
density: 100,
savename: "untitled",
savedir: "./images",
format: "png",
size: "600x600"
};
const convert = fromPath("/path/to/pdf/sample.pdf", options);
const pageToConvertAsImage = [4, 5]; // let's convert page 4 and 5
convert.bulk(pageToConvertAsImage).then((resolve) => {
console.log("Page 4 and 5 is now converted as image");
return resolve;
});
import { fromBuffer } from "pdf2pic";
import { readFileSync } from "fs";
const options = {
density: 100,
savename: "untitled",
savedir: "./images",
format: "png",
size: "600x600"
};
const file = readFileSync("/path/to/pdf/sample.pdf", "base64");
const buff = Buffer.from(file, "base64");
const convert = fromBuffer(buff, options);
const pageToConvertAsImage = 1;
convert(pageToConvertAsImage).then((resolve) => {
console.log("Page 1 is now converted as image");
return resolve;
});
import { fromBase64 } from "pdf2pic";
import { readFileSync } from "fs";
const options = {
density: 100,
savename: "untitled",
savedir: "./images",
format: "png",
size: "600x600"
};
const file = readFileSync("/path/to/pdf/sample.pdf", "base64");
const convert = fromBase64(file, options);
const pageToConvertAsImage = 1;
convert(pageToConvertAsImage).then((resolve) => {
console.log("Page 1 is now converted as image");
return resolve;
});
FAQs
A utility for converting pdf to image formats. Supports different outputs: directly to file, base64 or buffer.
The npm package pdf2pic receives a total of 69,813 weekly downloads. As such, pdf2pic popularity was classified as popular.
We found that pdf2pic demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.