|
@@ -495,6 +495,10 @@ public class FileUtils {
|
|
* @Date 2021.12.17 14:21
|
|
* @Date 2021.12.17 14:21
|
|
**/
|
|
**/
|
|
public static List<String> doForPageNumberUseItextpdf(List<String> uris, String localPath, NewIOSSClient newIOSSClient, Long projectId) {
|
|
public static List<String> doForPageNumberUseItextpdf(List<String> uris, String localPath, NewIOSSClient newIOSSClient, Long projectId) {
|
|
|
|
+ return doForPageNumberUseItextpdf(uris, localPath, newIOSSClient, projectId, 0, 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static List<String> doForPageNumberUseItextpdf(List<String> uris, String localPath, NewIOSSClient newIOSSClient, Long projectId, Integer pageType, Integer pageLen) {
|
|
List<String> result = new ArrayList<>();
|
|
List<String> result = new ArrayList<>();
|
|
if (uris != null && uris.size() > 0) {
|
|
if (uris != null && uris.size() > 0) {
|
|
int cursor = 0;
|
|
int cursor = 0;
|
|
@@ -563,19 +567,22 @@ public class FileUtils {
|
|
// heigh = temp;
|
|
// heigh = temp;
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
+ // 格式化页码
|
|
|
|
+ String pageNumber = formatPageNumber(cursor + index, pageType, pageLen);
|
|
|
|
+
|
|
if (width > heigh && heigh != 0) {
|
|
if (width > heigh && heigh != 0) {
|
|
//横表旋转270
|
|
//横表旋转270
|
|
pdfReader.getPageN(index).put(PdfName.ROTATE, new PdfNumber(270)); // 顺时针旋转270°
|
|
pdfReader.getPageN(index).put(PdfName.ROTATE, new PdfNumber(270)); // 顺时针旋转270°
|
|
//横表旋转后打页码坐标不一样
|
|
//横表旋转后打页码坐标不一样
|
|
- over.showTextAligned(Element.ALIGN_LEFT, String.valueOf(cursor + index), heigh - 35, 20, 0);
|
|
|
|
|
|
+ over.showTextAligned(Element.ALIGN_LEFT, pageNumber, heigh - 35, 20, 0);
|
|
} else {
|
|
} else {
|
|
if (rotate!= null && rotate.intValue() == 270) {
|
|
if (rotate!= null && rotate.intValue() == 270) {
|
|
//交换width和height
|
|
//交换width和height
|
|
pdfReader.getPageN(index).put(PdfName.ROTATE, new PdfNumber(0)); // 顺时针旋转270°
|
|
pdfReader.getPageN(index).put(PdfName.ROTATE, new PdfNumber(0)); // 顺时针旋转270°
|
|
//横表旋转后打页码坐标不一样
|
|
//横表旋转后打页码坐标不一样
|
|
- over.showTextAligned(Element.ALIGN_LEFT, String.valueOf(cursor + index), width - 35, 20, 0);
|
|
|
|
|
|
+ over.showTextAligned(Element.ALIGN_LEFT, pageNumber, width - 35, 20, 0);
|
|
}else {
|
|
}else {
|
|
- over.showTextAligned(Element.ALIGN_LEFT, String.valueOf(cursor + index), width - 35, 20, 0);
|
|
|
|
|
|
+ over.showTextAligned(Element.ALIGN_LEFT, pageNumber, width - 35, 20, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
over.endText();
|
|
over.endText();
|
|
@@ -838,4 +845,27 @@ public class FileUtils {
|
|
return cleaned.length() > 8 ? cleaned.substring(0, 8) : cleaned;
|
|
return cleaned.length() > 8 ? cleaned.substring(0, 8) : cleaned;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 格式化页码
|
|
|
|
+ * @param pageNumber 原始页码
|
|
|
|
+ * @param pageType 页码类型,0-默认无虚数,1-有虚数
|
|
|
|
+ * @param pageLen 页码位数
|
|
|
|
+ * @return 格式化后的页码
|
|
|
|
+ */
|
|
|
|
+ private static String formatPageNumber(int pageNumber, Integer pageType, Integer pageLen) {
|
|
|
|
+ if (pageType == null || pageType == 0) {
|
|
|
|
+ // 默认情况,直接返回页码
|
|
|
|
+ return String.valueOf(pageNumber);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (pageType == 1 && pageLen != null && pageLen > 0) {
|
|
|
|
+ // 需要补齐虚数
|
|
|
|
+ String format = "%0" + pageLen + "d";
|
|
|
|
+ return String.format(format, pageNumber);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 其他情况返回默认页码
|
|
|
|
+ return String.valueOf(pageNumber);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|