问题遇到的现象和发生背景
public static void main(String[] args) throws Exception{
splitPdf("https://res.ygyg.cn/userbusipub/M00/14/A1/CicmImJ2OGqAf1iXAc4gpYaD6HU101.pdf", 1);
}
public static void splitPdf(String filename, int splitSize) throws Exception {
PdfReader reader;
try {
reader = new PdfReader(filename, null, true);
} catch (IOException e) {
throw new Exception("读取PDF文件失败");
}
int numberOfPages = reader.getNumberOfPages();
int newFileCount = 0;
// PageNumber是从1开始计数的
int pageNumber = 1;
while (pageNumber <= numberOfPages) {
Document doc = new Document();
String splitFileName = filename.substring(0, filename.length() - 4) + "(" + newFileCount + ").pdf";
PdfCopy pdfCopy;
try {
pdfCopy = new PdfCopy(doc, new FileOutputStream(splitFileName));
} catch (FileNotFoundException | DocumentException e) {
throw new Exception("切割文件副本创建失败");
}
doc.open();
// 将pdf按页复制到新建的PDF中
for (int i = 1; pageNumber <= numberOfPages && i <= splitSize; ++i, pageNumber++) {
doc.newPage();
PdfImportedPage page = pdfCopy.getImportedPage(reader, pageNumber);
pdfCopy.addPage(page);
}
doc.close();
newFileCount++;
pdfCopy.close();
}
}
为什么是自己本地的PDF可以切割 但是以https为路径的PDF切割不了
如果想吧一个100页的大PDF 以每15页切割成一个小PDF怎么操作