'How to compress pdf file with nodejs?
I have tried to compress using ghostscript but no luck. Anyone has any alternative that is free and working?
Solution 1:[1]
var inputFile = req.body.path
outputFilePath = Date.now() + "output" + path.extname(req.body.path);
console.log(outputFilePath);
exec(
`gs \ -q -dNOPAUSE -dBATCH -dSAFER \ -sDEVICE=pdfwrite \ -dCompatibilityLevel=1.3 \ -dPDFSETTINGS=/ebook \ -dEmbedAllFonts=true \ -dSubsetFonts=true \ -dAutoRotatePages=/None \ -dColorImageDownsampleType=/Bicubic \ -dColorImageResolution=72 \ -dGrayImageDownsampleType=/Bicubic \ -dGrayImageResolution=72 \ -dMonoImageDownsampleType=/Subsample \ -dMonoImageResolution=72 \ -sOutputFile=${outputFilePath} \ ${inputFile}`,
(err, stdout, stderr) => {
if (err) {
res.json({
error: "some error takes place",
});
}
res.json({
path: outputFilePath,
});
}
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Muralidharan C |
