Java 如何使用PDFBox读取PDF文件内容中的特殊字符串

Java 如何使用PDFBox读取PDF文件内容中的特殊字符串,java,Java,我想写一个程序来提取论文中的主题、作者、摘要和其他信息。pdfbox可以做到吗?我应该怎么做?假设您已经将pdfbox jar添加到项目中,下面是用于检索PDF的一些基本文档属性的代码 import java.io.File; import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocumentInformation;

我想写一个程序来提取论文中的主题、作者、摘要和其他信息。pdfbox可以做到吗?我应该怎么做?

假设您已经将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();        
       }  
    }    

有关更多文档属性,请参阅。HTH.

我知道,但是通过这种方法我得到的大部分数据都是空的。谢谢你。它是空的。可能你加载的pdf不包含该值,请确认一下。我尝试过这段代码,它能够检索到所需的值。这段代码可以用这些元数据提取文档,但我要提取的文档不太规范,元数据几乎为空。现在我已经从正则表达式中提取了一些正则字段