0
我想分割一個PDF文件,我寫了代碼,我沒有任何錯誤,但沒有功能,我沒有收到文件。我的Pdf文檔有3頁,我希望在我的桌面上出現三頁一頁的文件。Api pdfbox-app-2.0.2我如何分割pdf文件?
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.apache.pdfbox.multipdf.Splitter;
import org.apache.pdfbox.pdmodel.PDDocument;
public class CutPDF {
private static File file ;
private static String filePath = "C:\\Users\\Desktop\\EmailTest.pdf";
public static void main(String[] args) throws IOException {
file = new File(filePath);
PDDocument document;
document = PDDocument.load(file);
Splitter splitter = new Splitter();
List<PDDocument> listOfSplitPages;
listOfSplitPages = splitter.split(document);
Iterator<PDDocument> iterator = listOfSplitPages.listIterator();
// I am using variable i to denote page numbers.
int i = 1;
while(iterator.hasNext()){
PDDocument pd = iterator.next();
// Saving each page with its assumed page no.
pd.save("C:\\Users\\Desktop " + i++ + ".pdf");
}
}
}
哇!謝謝 :) –