2009-09-04 70 views

回答

2

我可以推薦iText,它在處理PDF或甚至從頭開始構建它們時效果很好。

還有一個關於如何操作PDF的tutorial。我沒有看到刪除頁面的方法,但該工具支持通過複製另一個內容來創建新的PDF。所以你可以複製所有的頁面,但第一個。

1

隨着IText

public void removeFirstPage(String input_filename, String output_filename) throws DocumentException, IOException { 
    File outFile = new File(output_filename); 
    PdfReader reader = new PdfReader(input_filename); 
    int pages_number = reader.getNumberOfPages(); 
    if(pages_number > 0) { 
     Document document = new Document(reader.getPageSizeWithRotation(1)); 
     PdfCopy copy = new PdfCopy(document, new FileOutputStream(outFile)); 
     document.open(); 
    for(int i=2; i <= pages_number;i++) { 
      PdfImportedPage page = copy.getImportedPage(reader, i); 
     copy.addPage(page); 
    } 
     document.close();   
    } 
} 
相關問題