2014-04-08 1 views
0

안드로이드는이 코드를 사용하여 텍스트를 큰 소리로 말할 수있는 TextToSpeech라는 기능을 제공합니다. 안드로이드에서 모든 문장을 소리내어들을 수 있습니다. 여기에 text 변수를 저장안드로이드를 사용하여 PDF 파일로 TextToSpeech 기능

TextToSpeech tts= new TextToSpeech(this, this); 
int result = tts.setLanguage(Locale.US); 
tts.speak(**text**, TextToSpeech.QUEUE_FLUSH, null); 

문장들을 수 있지만, 내 문제는 내가 원하는이 단지 변수가 there.So을 통해 전체 PDF 또는 .DOC 파일을 배치하는 것입니다하지 않을 것입니다 때 내가 재생 버튼을 클릭하면 현재 PDF 또는 (모든 확장) android TextToSpeech 기능으로 소리내어 파일을 읽기 시작합니다. PDF 읽기 기능이있는 자습서를 사용하면 많은 도움이됩니다. 감사합니다.

+0

iText 또는 PDFBox를 사용하십시오. 그들은 Java에서 PDF 파일을 읽는 두 개의 주요 라이브러리입니다. – demongolem

+0

@demongolem 몇 가지 예를 들어 주시겠습니까? – rick

답변

0

Ok, PDFBox. 예 : here

import java.io.*; 
import org.apache.pdfbox.pdmodel.*; 
import org.apache.pdfbox.util.*; 

public class PDFTest { 

public static void main(String[] args){ 
PDDocument pd; 
BufferedWriter wr; 
try { 
     File input = new File("C:\\Invoice.pdf"); // The PDF file from where you would like to extract 
     File output = new File("C:\\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("CopyOfInvoice.pdf"); // Creates a copy called "CopyOfInvoice.pdf" 
     PDFTextStripper stripper = new PDFTextStripper(); 
     stripper.setStartPage(3); //Start extracting from page 3 
     stripper.setEndPage(5); //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(); 
     } 
    } 
} 

PDFStripper가 여기에 있습니다. PDF에서 텍스트를 추출합니다.