1.0.1 • Published 2 years ago
shrink-pdf v1.0.1
shrink-pdf
A tool to shrink PDF file sizes
Precondition
This tool requires two libraries, Ghostscript and ImageMagick, so install them first before using this tool.
ubuntu
apt install ghostscript
apt install imagemagickmacOS
brew install ghostscript
brew install imagemagickInstallation
npm install shrink-pdfCode Usage
const path = require("path");
const { shrink, shrink_by_page2jpg } = require("shrink-pdf");
const in_file = path.resolve(__dirname, "./test.pdf");
const out_file = path.resolve(__dirname, "./output.pdf");
let options = {
compatibilityLevel: 1.4,
imageQuality: 100,
resolution: 300,
in_file,
out_file
};
try {
shrink(options);
// Another function to shrink PDFs by converting each page to a JPG,
// resizing the JPGs smaller, then combining the resized JPGs into one PDF.
shrink_by_page2jpg({
...options,
resolution: 150,
out_file: path.resolve(__dirname, "./another_output.pdf"),
});
} catch (e) {
console.error(e);
}
process.exit();