|
@@ -463,6 +463,7 @@ public class FileUtils {
|
|
|
long s = System.currentTimeMillis();
|
|
|
String newurl = CommonUtil.replaceOssUrl(url);
|
|
|
PdfReader pdfReader = new PdfReader(newurl);
|
|
|
+
|
|
|
long e = System.currentTimeMillis();
|
|
|
log.info("读取pdf耗时:"+(e-s));
|
|
|
s = System.currentTimeMillis();
|
|
@@ -475,6 +476,13 @@ public class FileUtils {
|
|
|
String page = "page" + (cursor + 1);
|
|
|
do {
|
|
|
PdfContentByte over = pdfStamper.getOverContent(index);
|
|
|
+
|
|
|
+ PdfNumber rotate = null;
|
|
|
+ PdfDictionary pdfDictionary = pdfReader.getPageN(index);
|
|
|
+ if (pdfDictionary!= null) {
|
|
|
+ rotate = pdfDictionary .getAsNumber(PdfName.ROTATE);
|
|
|
+ }
|
|
|
+
|
|
|
if (over != null) {
|
|
|
over.beginText();
|
|
|
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
|
|
@@ -486,13 +494,27 @@ public class FileUtils {
|
|
|
int width = pa.getAsNumber(2).intValue();
|
|
|
int heigh = pa.getAsNumber(3).intValue();
|
|
|
|
|
|
- if (width > heigh) {
|
|
|
+// if (rotate!= null && rotate.intValue() == 270) {
|
|
|
+// //交换width和height
|
|
|
+// int temp = width;
|
|
|
+// width = heigh;
|
|
|
+// heigh = temp;
|
|
|
+// }
|
|
|
+
|
|
|
+ if (width > heigh && heigh != 0) {
|
|
|
//横表旋转270
|
|
|
pdfReader.getPageN(index).put(PdfName.ROTATE, new PdfNumber(270)); // 顺时针旋转270°
|
|
|
//横表旋转后打页码坐标不一样
|
|
|
over.showTextAligned(Element.ALIGN_LEFT, String.valueOf(cursor + index), heigh - 35, 20, 0);
|
|
|
} else {
|
|
|
- over.showTextAligned(Element.ALIGN_LEFT, String.valueOf(cursor + index), width - 35, 20, 0);
|
|
|
+ if (rotate!= null && rotate.intValue() == 270) {
|
|
|
+ //交换width和height
|
|
|
+ pdfReader.getPageN(index).put(PdfName.ROTATE, new PdfNumber(0)); // 顺时针旋转270°
|
|
|
+ //横表旋转后打页码坐标不一样
|
|
|
+ over.showTextAligned(Element.ALIGN_LEFT, String.valueOf(cursor + index), width - 35, 20, 0);
|
|
|
+ }else {
|
|
|
+ over.showTextAligned(Element.ALIGN_LEFT, String.valueOf(cursor + index), width - 35, 20, 0);
|
|
|
+ }
|
|
|
}
|
|
|
over.endText();
|
|
|
index++;
|