Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Archives
Today
Total
관리 메뉴

아님말고

PDFBOX를 이용한 PDF 텍스트 추출하기 본문

Parser

PDFBOX를 이용한 PDF 텍스트 추출하기

스타박씨 2009. 3. 10. 11:35

필요한 jar : PDFBox-0.7.3.jar , fontbox-0.1.0-dev.jar

view plaincopy to clipboardprint?
import java.io.File;  
import java.io.FileInputStream;  
import java.io.IOException;  
import java.io.InputStream;  
  
import org.pdfbox.cos.COSDocument;  
import org.pdfbox.pdfparser.PDFParser;  
import org.pdfbox.pdmodel.PDDocument;  
import org.pdfbox.util.PDFTextStripper;  
  
public class PDFTest {  
    public static void main(String[] args){  
        String src  = "D:\\study\\data\\test.pdf";  
        String text = null;  
        COSDocument cosDoc = null;  
        try{  
            File file  = new File(src);  
            InputStream is = new FileInputStream(file);  
              
            cosDoc = parseDocument(is);  
              
            PDFTextStripper striper = new PDFTextStripper();  
            text = striper.getText(new PDDocument(cosDoc));  
            System.out.println(text);  
        }catch(IOException e){  
            e.printStackTrace();  
        }  
    }  
      
    private static COSDocument parseDocument(InputStream is) throws IOException {  
        PDFParser parser = new PDFParser(is);  
        parser.parse();  
        return parser.getDocument();  
    }  
  
}​

'Parser' 카테고리의 다른 글

POI를 이용한 excel, word, powerpoint, visio 텍스트 추출  (1) 2009.03.09
NekoHTML 파서  (0) 2009.03.04
Comments