edit
This commit is contained in:
@@ -195,6 +195,11 @@
|
|||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
<version>1.2.24</version>
|
<version>1.2.24</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.luhuiguo</groupId>
|
||||||
|
<artifactId>aspose-pdf</artifactId>
|
||||||
|
<version>23.1</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.singularsys</groupId>
|
<groupId>com.singularsys</groupId>
|
||||||
<artifactId>jep</artifactId>
|
<artifactId>jep</artifactId>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package lingtao.net.util;
|
package lingtao.net.util;
|
||||||
|
|
||||||
|
import com.aspose.pdf.Document;
|
||||||
|
import com.aspose.pdf.optimization.OptimizationOptions;
|
||||||
import lingtao.net.bean.Product;
|
import lingtao.net.bean.Product;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -390,34 +392,30 @@ public class AStickersPrice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String path = "Z:\\设计文件共享中心\\已下单\\2019\\1月\\年后出货\\不干胶\\dy\\已拼";
|
String source = "C:\\Users\\231010\\Downloads\\蓝朝旺.pdf";
|
||||||
Path startPath = Paths.get(path);
|
String target = "C:\\Users\\231010\\Downloads\\蓝朝旺1.pdf";
|
||||||
try {
|
optimize(source, target);
|
||||||
Files.walk(startPath).filter(Files::isRegularFile).forEach(System.out::println);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String midStrEx(String source, String startStr, String endStr) {
|
public static void optimize(String source, String target) {
|
||||||
String result = "";
|
Document doc = new Document(source);
|
||||||
int startIndex, endIndex;
|
//设置压缩属性
|
||||||
try {
|
OptimizationOptions opt = new OptimizationOptions();
|
||||||
startIndex = source.indexOf(startStr);
|
//删除PDF不必要的对象
|
||||||
if (startIndex == -1) {
|
opt.setRemoveUnusedObjects(true);
|
||||||
|
//链接重复流
|
||||||
return result;
|
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);
|
||||||
}
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package lingtao.net.util;
|
package lingtao.net.util;
|
||||||
|
|
||||||
|
import com.aspose.pdf.Document;
|
||||||
|
import com.aspose.pdf.optimization.OptimizationOptions;
|
||||||
import lingtao.net.bean.Product;
|
import lingtao.net.bean.Product;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@@ -112,6 +114,9 @@ public class ZsPrice {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int[] twoSum(int[] nums, int target) {
|
public int[] twoSum(int[] nums, int target) {
|
||||||
|
|
||||||
List<Integer> list = new ArrayList<>();
|
List<Integer> list = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user