2017-11-30 31 views

答えて

0

は、あなたが以下の、プロジェクトにpdfbox jarを追加があると、あなたがより多くの文書のプロパティについてはPDF

import java.io.File; 
import java.io.IOException; 

import org.apache.pdfbox.pdmodel.PDDocument; 
import org.apache.pdfbox.pdmodel.PDDocumentInformation; 

    public class readPdf { 
     public static void main(String args[]) throws IOException { 

      //Loading an existing document 

      File file = new File("C:/Users/user1/Desktop/test.pdf"); 

      PDDocument document = PDDocument.load(file); 
      //Getting the PDDocumentInformation object 
      PDDocumentInformation pdd = document.getDocumentInformation(); 

      //Retrieving the info of a PDF document 
      System.out.println("Author of the document is :"+ pdd.getAuthor()); 
      System.out.println("Title of the document is :"+ pdd.getTitle()); 
      System.out.println("Subject of the document is :"+ pdd.getSubject()); 

      System.out.println("Creator of the document is :"+ pdd.getCreator()); 
      System.out.println("Creation date of the document is :"+ pdd.getCreationDate()); 
      System.out.println("Modification date of the document is :"+ 
      pdd.getModificationDate()); 
      System.out.println("Keywords of the document are :"+ pdd.getKeywords()); 

      //Closing the document 
      document.close();   
     } 
    }  

のための基本的な文書の属性の一部を取得するためのコードであるhereを参照してください。 HTH。

+0

私はそれを知っていますが、私が得るデータのほとんどはこのメソッドではnullです。すべて同じです。 – ZJR1994

+0

あなたがロードしたpdfに値が含まれていない可能性があります。確認してください。私はこのコードで試して、それは必要な値を取得することができます。 – Akjun

+0

このコードでは、これらのメタデータを使用してドキュメントを抽出できますが、抽出したいドキュメントは正式ではなく、メタデータはほとんどnullです。今、正規表現からいくつかの正規フィールドを抽出しました。 – ZJR1994

関連する問題