PDFParser extends AbstractParser implements Initializable { @Field public void setOcrStrategy(String ocrStrategyString) { defaultConfig.setOcrStrategy(ocrStrategyString); }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(
            InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context); PDFParserConfig getPDFParserConfig(); void setPDFParserConfig(PDFParserConfig config); boolean getEnableAutoSpace(); @Field void setEnableAutoSpace(boolean v); boolean getExtractAnnotationText(); void setExtractAnnotationText(boolean v); boolean getSuppressDuplicateOverlappingText(); @Field void setSuppressDuplicateOverlappingText(boolean v); boolean getSortByPosition(); @Field void setSortByPosition(boolean v); @Field void setOcrStrategy(String ocrStrategyString); @Field void setOcrImageType(String imageType); void setInitializableProblemHandler(InitializableProblemHandler initializableProblemHandler); @Field void setDropThreshold(float dropThreshold); @Field void setMaxMainMemoryBytes(long maxMainMemoryBytes); @Override void initialize(Map<String, Param> params); @Override void checkInitialization(InitializableProblemHandler handler); static final String PASSWORD; }
@Test public void testJBIG2OCROnly() throws Exception { assumeTrue("can run OCR", canRunOCR()); PDFParserConfig config = new PDFParserConfig(); config.setOcrStrategy(PDFParserConfig.OCR_STRATEGY.OCR_ONLY); ParseContext context = new ParseContext(); context.set(PDFParserConfig.class, config); XMLResult xmlResult = getXML("testPDF_JBIG2.pdf", context); assertContains("Norconex", xmlResult.xml); }
@Test public void testOCRAutoMode() throws Exception { assumeTrue("can run OCR", canRunOCR()); PDFParserConfig config = new PDFParserConfig(); config.setOcrStrategy(PDFParserConfig.OCR_STRATEGY.AUTO); ParseContext context = new ParseContext(); context.set(PDFParserConfig.class, config); XMLResult xmlResult = getXML("testOCR.pdf", context); assertContains("Happy New Year", xmlResult.xml); config.setOcrStrategy(PDFParserConfig.OCR_STRATEGY.NO_OCR); String txt = getText("testOCR.pdf", new Metadata(), context); assertEquals("", txt.trim()); }