[英]How to compress pdf file with nodejs?
I have tried to compress using ghostscript but no luck.我曾尝试使用 ghostscript 进行压缩,但没有运气。 Anyone has any alternative that is free and working?
有人有任何免费且有效的替代方案吗?
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,
});
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.