PagingPdfParser { public final void run() throws ParseException, CheckedOutOfMemoryError { PDDocument doc = null; try { doc = PDDocument.load(file); PagingStripper stripper = new PagingStripper(); stripper.setForceParsing(true); stripper.setSortByPosition(true); stripper.writeText(doc, writer); } catch (Exception e) { throw new ParseException(e); } catch (OutOfMemoryError e) { throw new CheckedOutOfMemoryError(e); } finally { PdfParser.close(doc); } } PagingPdfParser(@NotNull File file); final void run(); final void stop();  }
@Test public void testParse() throws ParseException, CheckedOutOfMemoryError { final List<String> pages = new ArrayList<String> (3); new PagingPdfParser(TestFiles.multi_page_pdf.get()) { protected void handlePage(String pageText) { pages.add(pageText); } }.run(); assertEquals(3, pages.size()); assertEquals("page 1" + Util.LS, pages.get(0)); assertEquals("page 2" + Util.LS, pages.get(1)); assertEquals("page 3" + Util.LS, pages.get(2)); }