赞
踩
依赖导入
com.itextpdf
itextpdf
5.5.13
org.apache.pdfbox
pdfbox
2.0.15
org.apache.pdfbox
fontbox
2.0.15
工具代码
import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
/**
* @author zh
* @data 2019/10/28 16:20
* 说明:TODO
*/
public class TestPDF {
public static void main(String[] args) throws IOException {
}
/**
* pdf拷贝到新文件,
* @param pdfFile
* @param newFile
* @param from 从第几页考
* @param end 考到第几页
*/
public static void copyPdfFile(String pdfFile, String newFile, int from, int end) {
Document document = null;
PdfCopy copy = null;
try {
PdfReader reader = new PdfReader(pdfFile);
int n = reader.getNumberOfPages();
if (end == 0) {
end = n;
}
ArrayList savepaths = new ArrayList();
String staticpath = pdfFile.substring(0, pdfFile.lastIndexOf("\\") + 1);
String savepath = staticpath + newFile;
savepaths.add(savepath);
document = new Document(reader.getPageSiz
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。