DocumentConversionService { public String tryOCRByConvertingToTiff(DNCWorkCoordinate coordinate, byte[] bytes) throws CanNotProcessCoordinateException { validateImageMagick(); File pdfFile = null; File tiffFile = null; try { pdfFile = File.createTempFile(coordinate.getFileName(), ".pdf"); FileUtils.writeByteArrayToFile(pdfFile, bytes); tiffFile = makeTiffFromPDF(coordinate, pdfFile); if (tiffFile == null) { throw new CanNotProcessCoordinateException("Could not convert PDF to Tiff: " + coordinate); } return getOCRResultFromTiff(tiffFile); } catch (Exception e) { logger.error(e.getMessage()); e.printStackTrace(); } finally { FileTools.deleteFiles(pdfFile, tiffFile); } throw new CanNotProcessCoordinateException("Could not convert PDF to Tiff: " + coordinate); }  String convertToText(byte[] data); String convertToXHTML(byte[] data); String tryOCRByConvertingToTiff(DNCWorkCoordinate coordinate, byte[] bytes); public Boolean imageMagickInstalled; }
@Test public void shouldTryOCRByConvertingToTiff() throws TikaException, IOException, SAXException, CanNotProcessCoordinateException { InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("test_ocr_pdf.pdf"); byte[] bytes = IOUtils.toByteArray(resourceAsStream); String text = service.tryOCRByConvertingToTiff(new DNCWorkCoordinate().sourceTable("table1"), bytes); System.out.println(text); assertTrue(text.contains("This is a random")); }