- 一个页拆分多个页,按照流水
String bank = "{\n" +
"\t\"bank\" : [\n" +
"\t\t{\n" +
"\t\t\t\"name\" : \"中国农业银行\",\n" +
"\t\t\t\"tableWidth\" : 279,\n" +
"\t\t\t\"split\" : 3\n" +
"\t\t},\n" +
"\t\t{\n" +
"\t\t\t\"name\" : \"中国银行\",\n" +
"\t\t\t\"tableWidth\" : 420,\n" +
"\t\t\t\"split\" : 2\n" +
"\t\t},\n" +
"\t\t{\n" +
"\t\t\t\"name\" : \"中国工商银行\",\n" +
"\t\t\t\"tableWidth\" : 414,\n" +
"\t\t\t\"split\" : 2\n" +
"\t\t}\n" +
"\t]\n" +
"}\n";
JSONObject jsonObject = JSONObject.parseObject(bank);
List<JSONObject> jsonObjectList = (List<JSONObject>) JSONPath.read(bank, "$bank[?(@.name='中国工商银行')]");
String filename = jsonObjectList.get(0).getString("name");
Integer tableWidth = jsonObjectList.get(0).getInteger("tableWidth");
Integer split = jsonObjectList.get(0).getInteger("split");
try (InputStream resource = new FileInputStream(new File("c:\\" + filename + ".pdf"));
OutputStream result = new FileOutputStream(new File("c:\\" + filename + "-split.pdf"))) {
Abstract2DPdfPageSplittingTool tool = new Abstract2DPdfPageSplittingTool() {
@Override
protected Iterable<Rectangle> determineSplitRectangles(PdfReader reader, int page) {
Rectangle targetSize = PageSize.A4;
List<Rectangle> rectangles = new ArrayList<>();
float pageHeight = targetSize.getHeight();
float pageWidth = targetSize.getWidth();
for (int i = 0; i < split; i++) {
rectangles.add(new Rectangle(0, pageHeight, pageWidth, pageHeight - tableWidth));
pageHeight = pageHeight - tableWidth;
}
return rectangles;
}
};
tool.split(result, new PdfReader(resource));
}
标签:账单,pageHeight,tableWidth,name,split,new,PDF,bank,多页
From: https://www.cnblogs.com/masg/p/16628550.html