Guest User

Untitled

a guest
Dec 8th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. File document = new File(strFile_path);
  2.  
  3. Parser parser = new AutoDetectParser();
  4. //PDFParser parser = new PDFParser();
  5. ContentHandler handler = new BodyContentHandler(Integer.MAX_VALUE);
  6. Metadata metadata = new Metadata();
  7.  
  8. PDFParserConfig config = new PDFParserConfig();
  9. // 太字などを文字を重ねることで表現している場合における重複文字を無視するかどうか
  10. config.setSuppressDuplicateOverlappingText(true);
  11. // テキスト下線などを無視するかどうか
  12. config.setExtractAnnotationText(false);
  13.  
  14. ParseContext context = new ParseContext();
  15. context.set(PDFParserConfig.class, new PDFParserConfig());
  16.  
  17. try {
  18. // 構文を解析するプログラムをパーサ呼ぶが、それを実行。
  19. parser.parse(new FileInputStream(document), handler, metadata, new ParseContext());
  20. }
  21. catch (FileNotFoundException e) {
  22. :
  23. }
  24. :
  25. catch (Exception e) {
  26. }
  27.  
  28. // PDFの文章を表示
  29. System.out.println("handler :[" + handler.toString() + "]");
  30.  
  31. context.set(PDFParserConfig.class, new PDFParserConfig());
  32.  
  33. context.set(PDFParserConfig.class, config);
  34.  
  35. try {
  36. // 構文を解析するプログラムをパーサ呼ぶが、それを実行。
  37. parser.parse(new FileInputStream(document), handler, metadata, new ParseContext());
  38.  
  39. try {
  40. // 構文を解析するプログラムをパーサ呼ぶが、それを実行。
  41. parser.parse(new FileInputStream(document), handler, metadata, context);
Add Comment
Please, Sign In to add comment