This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
PdfInforExtractor.java
50 lines (42 loc) · 1.67 KB
/
PdfInforExtractor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.ibm.sre.pdfparser;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
*
*
* This class illustrates how to use pdfparser to extract section information and table information
* from a given PDF file.
*
* @author yhou
*/
public class PdfInforExtractor {
public static Map<String, String> getPdfSections(String pdfFile) throws IOException, Exception {
GrobidPDFProcessor gp = GrobidPDFProcessor.getInstance();
Map<String, String> sections = gp.getPDFSectionAndText(pdfFile);
return sections;
}
public static List<CachedTable> getTableInfo(String pdfFile) throws IOException, Exception {
GrobidPDFProcessor gp = GrobidPDFProcessor.getInstance();
List<CachedTable> tables = gp.getTableInfoFromPDF(pdfFile);
return tables;
}
public static void main(String[] args) throws IOException, Exception{
String pdfPath = "/Users/yhou/git/kbp-science/data/pdfFile/D18-1440.pdf";
Map<String, String> sectionInfo = PdfInforExtractor.getPdfSections(pdfPath);
List<CachedTable> tableInfo = PdfInforExtractor.getTableInfo(pdfPath);
System.out.print("\n Section Info \n");
for(String sectionTitle: sectionInfo.keySet()){
System.out.println(sectionTitle + "--" + sectionInfo.get(sectionTitle));
}
System.out.println("\n table info\n");
for(CachedTable table: tableInfo){
System.out.println(table.caption);
}
}
}