Skip to content

Instantly share code, notes, and snippets.

@rahmaj
Last active March 17, 2018 14:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahmaj/7d5399d9519e9b15682c to your computer and use it in GitHub Desktop.
Save rahmaj/7d5399d9519e9b15682c to your computer and use it in GitHub Desktop.
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import net.sourceforge.tess4j.util.PdfUtilities;
public class TestOCR {
public void performOCR() throws TesseractException {
Tesseract instance = Tesseract.getInstance();
File pdfDoc = new File("/my/file/location/doc.pdf");
File pngImageFiles[] = PdfUtilities.convertPdf2Png(pdfDoc);
for (int i = 0; i < pngImageFiles.length; i++) {
String ocrResult = instance.doOCR(pngImageFiles[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment