解决方案
以下是使用 Java 将页面添加到 PDF 文档的示例程序。
import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
public class AddingPagesToPdf {
public static void main(String args[]) throws IOException {
//Creating PDF document object
PDDocument document = new PDDocument();
File file = new File("C:/pdfBox/AddPages.pdf");
PDDocument.load(file);
for (int i=0; i<10; i++){
//Creating a blank page
PDPage blankPage = new PDPage();
//Adding the blank page to the document
document.addPage(blankPage);
}
//Saving the document
document.save("C:/pdfBox/AddPages_OP.pdf");
System.out.println("PDF created");
//Closing the document
document.close();
}
}