PDFExtractor { @SneakyThrows public PDFDoc extractFromInputStream(InputStream is) { return extractResultFromInputStream(is).document; } PDFExtractor(Options opts);  PDFExtractor(); @SneakyThrows PdfDocExtractionResult extractResultFromInputStream(InputStream is); @SneakyThrows PdfDocExtractionResult extractResultFromPDDocument(PDDocument pdfBoxDoc); @SneakyThrows PDFDoc extractFromInputStream(InputStream is); public boolean DEBUG; }
@Test private void testCoordinates() { String pdfPath = "/coordinate_calibrator.pdf"; InputStream pdfInputStream = getClass().getResourceAsStream(pdfPath); PDFExtractor.Options opts = PDFExtractor.Options.builder().useHeuristicTitle(true).build(); PDFDoc doc = new PDFExtractor(opts).extractFromInputStream(pdfInputStream); for(PDFPage p : doc.pages) { for(PDFLine l : p.lines) { for(PDFToken t : l.tokens) { Assert.assertEquals(t.token, "M"); System.out.println("bounds x0: " + t.bounds.get(0) + " y0: " + t.bounds.get(1)); Assert.assertTrue(t.bounds.get(0) < 0.1); Assert.assertTrue(t.bounds.get(1) < 0.1); } } } }
@Test public void testSuperscript() throws Exception { String pdfPath = "/superscripttest.pdf"; InputStream pdfInputStream = getClass().getResourceAsStream(pdfPath); PDFExtractor.Options opts = PDFExtractor.Options.builder().useHeuristicTitle(true).build(); PDFDoc doc = new PDFExtractor(opts).extractFromInputStream(pdfInputStream); doc = doc.withoutSuperscripts(); for(PDFPage p : doc.pages) { for(PDFLine l : p.lines) { for(PDFToken t : l.tokens) { if(t.token.startsWith("SHEIKHAHMADI")) Assert.assertEquals(t.token, "SHEIKHAHMADI,"); if(t.token.startsWith("(CN")) { Assert.assertEquals(t.token, "(CN)"); break; } } } } }