代码如下
package com.hyzs.szcg.doc.utils;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import lombok.extern.slf4j.Slf4j;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Slf4j
public class PdfUtils {
//给pdf增加页码
public static boolean createFooter(String pdfPath, String newfile) {
boolean retValue = false;
Document document=null;
try {
document=new Document(new PdfReader(pdfPath).getPageSize(1));
PdfCopy copy=new PdfCopy(document,new FileOutputStream(newfile));
document.open();
int pagesNum=0;//总页码
int pages=0;//当前页码
PdfReader reader=new PdfReader(pdfPath);
pagesNum+=reader.getNumberOfPages();
PdfCopy.PageStamp stamp;//插入页码所需 不要页码