|
|
@@ -1,5 +1,7 @@
|
|
|
package lingtao.net.util;
|
|
|
|
|
|
+import com.aspose.pdf.Document;
|
|
|
+import com.aspose.pdf.optimization.OptimizationOptions;
|
|
|
import lingtao.net.bean.Product;
|
|
|
|
|
|
import java.io.File;
|
|
|
@@ -390,34 +392,30 @@ public class AStickersPrice {
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- String path = "Z:\\设计文件共享中心\\已下单\\2019\\1月\\年后出货\\不干胶\\dy\\已拼";
|
|
|
- Path startPath = Paths.get(path);
|
|
|
- try {
|
|
|
- Files.walk(startPath).filter(Files::isRegularFile).forEach(System.out::println);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ String source = "C:\\Users\\231010\\Downloads\\蓝朝旺.pdf";
|
|
|
+ String target = "C:\\Users\\231010\\Downloads\\蓝朝旺1.pdf";
|
|
|
+ optimize(source, target);
|
|
|
}
|
|
|
|
|
|
- public static String midStrEx(String source, String startStr, String endStr) {
|
|
|
- String result = "";
|
|
|
- int startIndex, endIndex;
|
|
|
- try {
|
|
|
- startIndex = source.indexOf(startStr);
|
|
|
- if (startIndex == -1) {
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
- String tmpStr = source.substring(startIndex + startStr.length());
|
|
|
- endIndex = tmpStr.indexOf(endStr);
|
|
|
- if (endIndex == -1) {
|
|
|
- return result;
|
|
|
- }
|
|
|
- result = tmpStr.substring(0, endIndex);
|
|
|
- } catch (Exception ex) {
|
|
|
- System.out.println("MidStrEx Err: " + ex.getMessage());
|
|
|
- }
|
|
|
- return result;
|
|
|
+ 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(100);
|
|
|
+ doc.optimizeResources(opt);
|
|
|
+ //优化web的PDF文档
|
|
|
+ doc.optimize();
|
|
|
+ doc.save(target);
|
|
|
}
|
|
|
-
|
|
|
}
|