pdf文件压缩
添加依赖
<dependency><groupId>com.luhuiguo</groupId><artifactId>aspose-pdf</artifactId><version>23.1</version>
</dependency>
public class OptimizePdf {public static void optimize(String source, String target) {Document doc = new Document(source);//设置压缩属性OptimizationOptions opt = new OptimizationOptions();//删除PDF不必要的对象opt.setRemoveUnusedObjects(true);//链接重复流opt.setLinkDuplcateStreams(false);//删除未使用的流opt.setRemoveUnusedStreams(false);//删除不必要的字体opt.setUnembedFonts(true);//压缩PDF中的图片opt.getImageCompressionOptions().setCompressImages(true);//图片压缩比, 0 到100可选,越低压缩比越大opt.getImageCompressionOptions().setImageQuality(50);doc.optimizeResources(opt);//优化web的PDF文档doc.optimize();doc.save(target);}public static void main(String[] args) {String source = "/Users/zhanghe/Desktop/2.pdf";String target = "/Users/zhanghe/Desktop/1.pdf";optimize(source, target);}
}
参考文献
- pdf文件压缩
本文由mdnice多平台发布