sdcard에서 pdf 파일을 읽으려고 시도하고 텍스트를 추출하면 아무 일도 일어나지 않습니다. 오류, 경고, 알림 및 결과 파일이 없습니다. 소스 파일과 결과를 모두 장치 sdcard의 루트 폴더에 저장했습니다. 이 문제를 해결할 수 있도록 도와 주시겠습니까?iTextG를 사용하여 안드로이드에서 pdf 파일의 텍스트를 추출하십시오
그리고 여기에 내가 AVD에 그것을 테스트 때 (나는 그것을 도울 수있는 희망) 콘솔 탭에 보여 것입니다
package com.example.androidtest;
import java.io.File;
...
public class MainActivity extends Activity {
private Button button;
public static final String TIMETABLE = "doc.pdf"; // The original PDF that will be parsed.
public static final String RESULT = "timetable.txt"; // The text file received after scan.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
processSource();
}
public void processSource() {
button = (Button) this.findViewById(R.id.button_add);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
new MainActivity().extractText(TIMETABLE, RESULT);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public void extractText(String pdf, String doc) throws IOException {
File sdcard = Environment.getExternalStorageDirectory(); // Load file timetable.txt from device's sdcard
File file = new File(sdcard, pdf);
File text = new File(sdcard, doc); // Save the result file in device's sdcard
InputStream is;
try {
is = new FileInputStream(file);
PdfReader reader = new PdfReader(is); // Call the source file
PrintWriter out = new PrintWriter(new FileOutputStream(text));
Rectangle rect = new Rectangle(0, 0, 600, 900); // Define the rectangle to extract text within it
RenderFilter filter = new RegionTextRenderFilter(rect);
TextExtractionStrategy strategy = new FilteredTextRenderListener(new LocationTextExtractionStrategy(), filter);
out.println(PdfTextExtractor.getTextFromPage(reader, 1, strategy));
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // Call the source file
}
} : 다음은 내 코드입니다
[2013 -11-23 03:03:29 - AndroidTest] Android 시작! [2013-11-23 03:03:29 - AndroidTest] adb이 정상적으로 실행되고 있습니다. [2013-11-23 03:03:29 - AndroidTest] com.example.androidtest.MainActivity> 활동 시작 [2013-11-23 03:03:29 - AndroidTest] 자동 타겟 모드 : 새로운 에뮬레이터 시작> 호환 가능한 AVD '탭' [2013-11-23 03:03:29 - AndroidTest] 가상 장치 'Tab'을 사용하여 새로운 에뮬레이터 시작 [2013-11-23 03:03:29 - AndroidTest] 새 에뮬레이터 발견 : 에뮬레이터 -5554 [2013-11-23 03:03:29 - AndroidTest] 홈 ('android.process.acore') 대기 시작> 시작했습니다 ... [2013-11-23 03:03:57 - AndroidTest ] 'emulator-5554'에 홈이 있습니다. [2013-11-23 03:03:57 - AndroidTest] '에뮬레이터 -5554'에 AndroidTest.apk 업로드 [2013-11-23 03:04:06 - AndroidTest] AndroidTest.apk 설치 ... [2013-11-23 03:04 : 29 - AndroidTest] 성공! [2013-11-23 03:04:29 - AndroidTest] 시작 활동> com.example.androidtest.MainActivity on device emulator-5554 [2013-11-23 03:04:30 - AndroidTest] ActivityManager : 시작 : 의도 > {행위 = android.intent.action.MAIN 고양이 = [android.intent.category.LAUNCHER]> CMP = com.example.androidtest/.MainActivity} 시간 내
감사합니다! (0, 0)
에서의 왼쪽 하단 모서리를 가질 필요가 없습니다
Rectangle rect = new Rectangle(0, 0, 600, 900);
// Define the rectangle to extract text within it
RenderFilter filter = new RegionTextRenderFilter(rect);
를 PDF 페이지 :