首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

关于pdf解析 PdfBox解析提取题目作者时不对

2012-12-31 
关于pdf解析 PdfBox解析提取标题作者时不对我现在想做一个pdf文献搜索系统,需要解析pdf从中提取文献中的作

关于pdf解析 PdfBox解析提取标题作者时不对
我现在想做一个pdf文献搜索系统,需要解析pdf  从中提取文献中的作者名 标题 期刊名 keywords 作为索引域。使用pdfbox的api 但是提取的内容不是想要的。那位帮我解决一下。谢谢! 

我的代码:
PDDocument pDoc=new PDDocument(cosDoc);
try{
PDDocumentInformation docInfo = pDoc.getDocumentInformation();
if(docInfo != null){
String author = docInfo.getAuthor();
System.out.println("author" +author);
String title = docInfo.getTitle();
String summary = docInfo.getSubject();
String keywords = docInfo.getKeywords();
System.out.println("Author      " +author);
System.out.println("Title     " +title);
System.out.println("Summary     " +summary);
System.out.println("Keywords     " +keywords);

if(!author.isEmpty()){
doc.add(new Field("author",author,Field.Store.NO,Field.Index.ANALYZED));

}
if(!title.isEmpty()){
doc.add(new Field("title",title,Field.Store.NO,Field.Index.ANALYZED));
}
if(!summary.isEmpty()){

doc.add(new Field("summary",summary,Field.Store.NO,Field.Index.ANALYZED));
}
if(!keywords.isEmpty()){
doc.add(new Field("keywords",keywords,Field.Store.NO,Field.Index.ANALYZED));
}
}
}catch(Exception e){
closeCOSDocument(cosDoc);
closePDDocument(pDoc);
System.err.println("cannot get pdf meta-data" +e.getMessage());

}
return doc;
}

private static COSDocument parseDocument(FileInputStream is) throws IOException{
PDFParser parser=new PDFParser(is);
parser.parse();
return parser.getDocument();
}

private static void closeCOSDocument(COSDocument cosDoc){
if(cosDoc != null){
try{
cosDoc.close();
}catch(IOException e){
//
}
}
}

private static void closePDDocument(PDDocument pdDoc){
if(pdDoc != null){
try{
pdDoc.close();
}catch(IOException e){
//
}
}
}


运行报错  红字部分
authorxcannot get pdf meta-datanull

Author      x
Title     3.1 Editorials.indd Colin.indd
Summary     null
Keywords     null
authorx
Author      x
Title     3.1 N&V NR IF.indd
Summary     null
Keywords     null
cannot get pdf meta-datanull
authorx
Author      x
Title     3.1 Editorials.indd Colin.indd
Summary     null
Keywords     null
cannot get pdf meta-datanull
Optimizing index...
3271 total milliseconds
 Documents 3
我想知道是代码的原因      还是 pdfbox的原因
[解决办法]
不懂,关注一下
[解决办法]
不知道楼主对pdf文件的自动生成的功力如何?

现在我接手的一个项目中,有相关的开发内容。与pdf有关的需求是:根据各家用户的定义文档格式(由于用户的行业背景不一样,所以定义格式会有相当大的差别,这一点,希望楼主心里有数),将其他来源的结果数据,准确填入到格式文件中,最终将合成结果生成pdf格式文件。至于此项目别的接口已经封装完毕,可直接通过API函数或临时文件两种方式握手通讯。



不能以第三方付费库作为开发基础。

楼主或其他觉得有能力之人也欢迎联系,QQ:576130598
[解决办法]
不知道楼主对pdf文件的自动生成的功力如何? 

现在我接手的一个项目中,有相关的开发内容。与pdf有关的需求是:根据各家用户的定义文档格式(由于用户的行业背景不一样,所以定义格式会有相当大的差别,这一点,希望楼主心里有数),将其他来源的结果数据,准确填入到格式文件中,最终将合成结果生成pdf格式文件。至于此项目别的接口已经封装完毕,可直接通过API函数或临时文件两种方式握手通讯。 

不能以第三方付费库作为开发基础。 

[解决办法]
我虽然没用过,但觉得应该是在meta-data文件中可以自定义PDF文档的各种信息的存储格式。
而你没有进行自定义,所以会报错,虽然PDFbox按照默认的格式去读取,但你的文档在创建时可能就没有写进去这些信息。只是在文档内容中写了东西。。
就好像我们默认在书的封面上寻找作者,但你出了一本书,偏偏封面没有作者,作者信息写在了里面,这样,PDFbox当然就会填为空白了。。
以上只是我的猜测而已,你再请教吧

热点排行