目录

如何使用Java将页面添加到PDF文档。(How to add pages to a PDF document using Java.)

问题描述 (Problem Description)

如何使用Java将页面添加到PDF文档。

解决方案 (Solution)

以下是使用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(); 
   }  
}

输入 (Input)

添加PDF输入

输出 (Output)

添加PDF输出
↑回到顶部↑
WIKI教程 @2018