|
|
@@ -6,8 +6,6 @@ import lombok.AllArgsConstructor;
|
|
|
import lombok.Data;
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-
|
|
|
/**
|
|
|
* @author jingyuanchao
|
|
|
* @date 2023/12/18 20:18
|
|
|
@@ -22,6 +20,8 @@ public class PdfPageHelperEvent implements PdfPageEvent {
|
|
|
private PdfWriter writer;
|
|
|
|
|
|
private BaseFont fs;
|
|
|
+
|
|
|
+
|
|
|
private Font tableFont;
|
|
|
|
|
|
@Override
|
|
|
@@ -40,20 +40,43 @@ public class PdfPageHelperEvent implements PdfPageEvent {
|
|
|
|
|
|
@Override
|
|
|
public void onEndPage(PdfWriter pdfWriter, Document document) {
|
|
|
- PdfContentByte cb = writer.getDirectContent();// 得到层
|
|
|
+ /* PdfContentByte cb = writer.getDirectContent();// 得到层
|
|
|
cb.saveState(); // 开始
|
|
|
cb.beginText();
|
|
|
cb.setFontAndSize(fs, 10); // Header
|
|
|
- /* float x = document.top(-20);// 位置 // 左
|
|
|
+ *//* float x = document.top(-20);// 位置 // 左
|
|
|
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, "H-Left", document.left(), x, 0); // 中
|
|
|
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "第" + writer.getCurrentPageNumber() + "页", (document.right() + document.left()) / 2, x, 0); // 右
|
|
|
- cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, "H-Right", document.right(), x, 0); */
|
|
|
+ cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, "H-Right", document.right(), x, 0); *//*
|
|
|
float y = document.bottom(-80); // 左
|
|
|
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, "", document.left(), y, 0); // 中
|
|
|
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "第" + writer.getCurrentPageNumber() + "页/共" + totalPageSize + "页", (document.right() + document.left()) / 2, y, 0); // 右
|
|
|
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, "", document.right(), y, 0);
|
|
|
cb.endText();
|
|
|
- cb.restoreState();
|
|
|
+ cb.restoreState();*/
|
|
|
+
|
|
|
+ try {
|
|
|
+ // PDF文档内容
|
|
|
+ PdfContentByte pdfContent = writer.getDirectContent();
|
|
|
+ pdfContent.saveState();
|
|
|
+ pdfContent.beginText();
|
|
|
+ int footerFontSize = 10;
|
|
|
+ Font fontDetail = new Font(fs, footerFontSize, Font.NORMAL);
|
|
|
+ pdfContent.setFontAndSize(fs, footerFontSize);
|
|
|
+ // 页脚的页码 展示
|
|
|
+ String footerNum = String.format("第%d页,共" + totalPageSize + "页", writer.getPageNumber());
|
|
|
+ Phrase phrase = new Phrase(footerNum, fontDetail);
|
|
|
+ // 页码的 横轴 坐标 居中
|
|
|
+ float x = (document.left() + document.right()) / 2 + 10;
|
|
|
+ // 页码的 纵轴 坐标
|
|
|
+ float y = document.bottom(-20);
|
|
|
+ // 添加文本内容,进行展示页码
|
|
|
+ ColumnText.showTextAligned(pdfContent, Element.ALIGN_CENTER, phrase, x, y, 0);
|
|
|
+ pdfContent.endText();
|
|
|
+ pdfContent.restoreState();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|