|
@@ -186,6 +186,44 @@ public class OfficeUtil1 {
|
|
|
}
|
|
|
doc.head().appendElement("style").text(baseCss);
|
|
|
|
|
|
+// int groupId = 0;
|
|
|
+// for (Element row : doc.select("tr:has(td[rowspan], th[rowspan])")) {
|
|
|
+// int rowspan = Integer.parseInt(row.select("[rowspan]").first().attr("rowspan"));
|
|
|
+// row.attr("data-group-id", String.valueOf(groupId++));
|
|
|
+//
|
|
|
+// // 标记被rowspan覆盖的行
|
|
|
+// Element nextRow = row.nextElementSibling();
|
|
|
+// for (int i = 1; i < rowspan && nextRow != null; i++) {
|
|
|
+// nextRow.attr("data-group-child", "true");
|
|
|
+// nextRow = nextRow.nextElementSibling();
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// doc.head().appendElement("style")
|
|
|
+// .text("tr[data-group-id], tr[data-group-child] { "
|
|
|
+// + "page-break-inside: avoid !important; "
|
|
|
+// + "}");
|
|
|
+
|
|
|
+// //合并单元格的处理
|
|
|
+// Elements rowsWithRowspan = doc.select("tr:has(td[rowspan], th[rowspan])");
|
|
|
+//
|
|
|
+// // 遍历所有包含合并单元格的行
|
|
|
+// for (Element row : rowsWithRowspan) {
|
|
|
+// // 找到合并单元格的跨行数
|
|
|
+// int rowspan = Integer.parseInt(row.select("td[rowspan], th[rowspan]").first().attr("rowspan"));
|
|
|
+//
|
|
|
+// // 创建新的 tbody 包裹当前行及后续受影响的行
|
|
|
+// Element tbody = new Element("tbody").attr("style", "page-break-inside: avoid; width: 100%;");
|
|
|
+// for (int i = 0; i < rowspan; i++) {
|
|
|
+// Element nextRow = row.nextElementSibling();
|
|
|
+// row.before(tbody);
|
|
|
+// tbody.appendChild(row);
|
|
|
+// if (nextRow != null) {
|
|
|
+// row = nextRow; // 处理后续行
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
Elements tds = doc.select("td");
|
|
|
for (Element td : tds) {
|
|
|
Elements ps = td.select("p");
|
|
@@ -311,6 +349,10 @@ public class OfficeUtil1 {
|
|
|
for (Element element : select9) {
|
|
|
element.attr("style", element.attr("style") + "word-break: break-all; overflow-wrap: anywhere; max-width: 100%;");
|
|
|
}
|
|
|
+ Elements select8 = doc.select("p.X1.X8");
|
|
|
+ for (Element element : select8) {
|
|
|
+ element.attr("style", element.attr("style") + "word-break: break-all; overflow-wrap: anywhere; max-width: 100%;");
|
|
|
+ }
|
|
|
//1.3合并的单元格 不分页
|
|
|
Elements select11 = doc.select("td.X10.X11");
|
|
|
for (Element element : select11) {
|
|
@@ -531,10 +573,11 @@ public class OfficeUtil1 {
|
|
|
String backgroundImagePath, boolean onlyCollectPageNumbers)
|
|
|
throws Exception {
|
|
|
PdfReader reader = new PdfReader(inputPdfPath);
|
|
|
+
|
|
|
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputPdfPath));
|
|
|
int startPage = 1;
|
|
|
if (onlyCollectPageNumbers) {
|
|
|
-pageNumberMap.clear();
|
|
|
+ pageNumberMap.clear();
|
|
|
Pattern startPattern = Pattern.compile("^1\\.\\s+报告概述$");
|
|
|
|
|
|
// 查找起始页
|
|
@@ -649,4 +692,21 @@ pageNumberMap.clear();
|
|
|
reader.close();
|
|
|
}
|
|
|
|
|
|
+// private static boolean isTableNearBottom(PdfWriter writer, PdfPTable table, float bottom) {
|
|
|
+// try {
|
|
|
+// // 获取当前页面的剩余高度
|
|
|
+// float remainingHeight = writer.getVerticalPosition(true) - bottom;
|
|
|
+//
|
|
|
+// // 估算当前行高度
|
|
|
+// float estimatedRowHeight = 30f;
|
|
|
+// float estimatedTableHeight = table.getRows().size() * estimatedRowHeight;
|
|
|
+//
|
|
|
+// // 如果剩余空间不足以容纳整个表格,则换页
|
|
|
+// return remainingHeight < estimatedTableHeight;
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// return false;
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
}
|