Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
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",
width: 600,
height: 600
};
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",
width: 600,
height: 600
};
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",
width: 600,
height: 600
};
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",
width: 600,
height: 600
};
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,067 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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.