2016-04-16 67 views
1

私はpdfファイル(その一部を以下に示します)を持っており、そこからテキストを抽出したいと考えています。 PDFTextStreamを使用しましたが、このファイルでは機能しません。 (しかし、それは単純なテキストを持つ他のファイルで動作します)。Java - OCRを使用したPDFからのテキストの抽出

その他のOCRライブラリにはどのような機能がありますか?

お願いします。 ありがとうございます。

Glimpses of pdf file

glipmses of pdf file

+0

あなたのPDFはちょうど原稿のスキャンした紙のコピーが含まれていますか?特にOCRのような複雑な文書では、100%正確な結果を期待できません。テキストと行が多くの場所で重なっているのは大きな問題です。アルゴリズムが個々のグリフを区別することは非常に困難です。 –

+0

@HåkenLidテキストと行が重なり合っていないため、拡大して表示されます。 – Dax

+0

@HåkenLidこの文書はOCRにとって複雑すぎるのですか?しかし、私はすべてのテキストを必要としません。私は名前、アドレス(上のセクションから)と過去の会費/払い戻しテーブルを抽出するだけです。 – Dax

答えて

1

IはPDFBoxと試み、それが満足のいく結果が得られました。ここで

はPDFBoxを使用してPDFからテキストを抽出するためのコードです:

import java.io.*; 

import org.apache.pdfbox.pdmodel.*; 
import org.apache.pdfbox.text.PDFTextStripper; 
import org.apache.pdfbox.util.*; 

public class PDFTest { 

public static void main(String[] args){ 
PDDocument pd; 
BufferedWriter wr; 
try { 
     File input = new File("C:/BillOCR/data/bill.pdf"); // The PDF file from where you would like to extract 
     File output = new File("D:/SampleText.txt"); // The text file where you are going to store the extracted data 
     pd = PDDocument.load(input); 
     System.out.println(pd.getNumberOfPages()); 
     System.out.println(pd.isEncrypted()); 
     pd.save("CopyOfBill.pdf"); // Creates a copy called "CopyOfInvoice.pdf" 
     PDFTextStripper stripper = new PDFTextStripper(); 
     stripper.setStartPage(1); //Start extracting from page 3 
     stripper.setEndPage(1); //Extract till page 5 
     wr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output))); 
     stripper.writeText(pd, wr); 
     if (pd != null) { 
      pd.close(); 
     } 
     // I use close() to flush the stream. 
     wr.close(); 
} catch (Exception e){ 
     e.printStackTrace(); 
     } 
    } 
} 
+1

OCRはまったく必要ありませんでした。 –

関連する問題