当前位置: 首页>>代码示例>>Java>>正文


Java PDFParserConfig类代码示例

本文整理汇总了Java中org.apache.tika.parser.pdf.PDFParserConfig的典型用法代码示例。如果您正苦于以下问题:Java PDFParserConfig类的具体用法?Java PDFParserConfig怎么用?Java PDFParserConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PDFParserConfig类属于org.apache.tika.parser.pdf包,在下文中一共展示了PDFParserConfig类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: PDFExtract

import org.apache.tika.parser.pdf.PDFParserConfig; //导入依赖的package包/类
public PDFExtract(){
    parser = new AutoDetectParser();
    TesseractOCRConfig config = new TesseractOCRConfig();
    PDFParserConfig pdfConfig = new PDFParserConfig();
    pdfConfig.setExtractInlineImages(true);

    parseContext = new ParseContext();
    parseContext.set(TesseractOCRConfig.class, config);
    parseContext.set(PDFParserConfig.class, pdfConfig);
    //need to add this to make sure recursive parsing happens!
    parseContext.set(Parser.class, parser);
}
 
开发者ID:thammegowda,项目名称:pdf-extractor,代码行数:13,代码来源:PDFExtract.java

示例2: Extractor

import org.apache.tika.parser.pdf.PDFParserConfig; //导入依赖的package包/类
/**
 * Create a new extractor, which will OCR images by default if Tesseract is available locally, extract inline
 * images from PDF files and OCR them and use PDFBox's non-sequential PDF parser.
 */
public Extractor() {

	// Calculate the SHA256 digest by default.
	setDigestAlgorithms(DigestAlgorithm.SHA256);

	// Run OCR on images contained within PDFs and not on pages.
	pdfConfig.setExtractInlineImages(true);
	pdfConfig.setOcrStrategy(PDFParserConfig.OCR_STRATEGY.NO_OCR);

	// By default, only the object IDs are used for determining uniqueness.
	// In scanned documents under test from the Panama registry, different embedded images had the same ID, leading to incomplete OCRing when uniqueness detection was turned on.
	pdfConfig.setExtractUniqueInlineImagesOnly(false);

	// Set a long OCR timeout by default, because Tika's is too short.
	setOcrTimeout(Duration.ofDays(1));
	ocrConfig.setEnableImageProcessing(0); // See TIKA-2167. Image processing causes OCR to fail.

	// English text recognition by default.
	ocrConfig.setLanguage("eng");
}
 
开发者ID:ICIJ,项目名称:extract,代码行数:25,代码来源:Extractor.java

示例3: buildParseContext

import org.apache.tika.parser.pdf.PDFParserConfig; //导入依赖的package包/类
@Override
protected ParseContext buildParseContext(Metadata metadata, String targetMimeType, TransformationOptions options)
{
    ParseContext context = super.buildParseContext(metadata, targetMimeType, options);
    if (pdfParserConfig != null)
    {
        context.set(PDFParserConfig.class, pdfParserConfig);
    }
    // TODO: Possibly extend TransformationOptions to allow for per-transform PDFParserConfig?
    return context;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:12,代码来源:PdfBoxContentTransformer.java

示例4: fromFile

import org.apache.tika.parser.pdf.PDFParserConfig; //导入依赖的package包/类
@Override
public String fromFile(File file) {
	String resultText = "";

	try {
		FileInputStream inputstream = new FileInputStream(file);
		BodyContentHandler handler = new BodyContentHandler(-1);
		Metadata metadata = new Metadata();
		ParseContext pcontext = new ParseContext();

		PDFParserConfig config = new PDFParserConfig();
		config.setSortByPosition(true);

		PDFParser pdfparser = new PDFParser();
		pdfparser.setPDFParserConfig(config);
		
		System.out.println("Parsing PDF to TEXT...");
		
		pdfparser.parse(inputstream, handler, metadata, pcontext);
		resultText = handler.toString();
		
		System.out.println("Parsing complete");
	} catch (Exception ex) {
		throw new RuntimeException(ex);
	}

	return resultText;
}
 
开发者ID:eduardohmg,项目名称:diario-extractor,代码行数:29,代码来源:PDFToTextImpl.java

示例5: fillParseContext

import org.apache.tika.parser.pdf.PDFParserConfig; //导入依赖的package包/类
private static void fillParseContext(ParseContext parseContext, Map<String, Object> options) {
	final TesseractOCRConfig ocrConfig = new TesseractOCRConfig();

	if (options == null) {

		// Disable OCR and return if no options are specified.
		disableOcr(ocrConfig);
		parseContext.set(TesseractOCRConfig.class, ocrConfig);

		return;
	}

	fillOcrOptions(ocrConfig, options);
	parseContext.set(TesseractOCRConfig.class, ocrConfig);

	final PDFParserConfig pdfParserConfig = new PDFParserConfig();
	fillPdfOptions(pdfParserConfig, options);
	parseContext.set(PDFParserConfig.class, pdfParserConfig);

	// Allow a password to be specified for encrypted files.
	fillPassword(parseContext, options);
}
 
开发者ID:ICIJ,项目名称:node-tika,代码行数:23,代码来源:NodeTika.java

示例6: extract

import org.apache.tika.parser.pdf.PDFParserConfig; //导入依赖的package包/类
/**
 * Create a pull-parser from the given {@link TikaInputStream}.
 *
 * @param input the stream to extract from
 * @param document file that is being extracted from
 * @return A pull-parsing reader.
 */
protected Reader extract(final Document document, final TikaInputStream input) throws IOException {
	final Metadata metadata = document.getMetadata();
	final ParseContext context = new ParseContext();
	final AutoDetectParser autoDetectParser = new AutoDetectParser(defaultParser);
	final Parser parser;

	if (null != digester) {
		parser = new DigestingParser(autoDetectParser, digester);
	} else {
		parser = autoDetectParser;
	}

	if (!ocrDisabled) {
		context.set(TesseractOCRConfig.class, ocrConfig);
	}

	context.set(PDFParserConfig.class, pdfConfig);

	// Set a fallback parser that outputs an empty document for empty files,
	// otherwise throws an exception.
	autoDetectParser.setFallback(FallbackParser.INSTANCE);

	// Only include "safe" tags in the HTML output from Tika's HTML parser.
	// This excludes script tags and objects.
	context.set(HtmlMapper.class, DefaultHtmlMapper.INSTANCE);

	final Reader reader;
	final Function<Writer, ContentHandler> handler;

	if (OutputFormat.HTML == outputFormat) {
		handler = (writer) -> new ExpandedTitleContentHandler(new HTML5Serializer(writer));
	} else {

		// The default BodyContentHandler is used when constructing the ParsingReader for text output, but
		// because only the body of embeds is pushed to the content handler further down the line, we can't
		// expect a body tag.
		handler = WriteOutContentHandler::new;
	}

	if (EmbedHandling.SPAWN == embedHandling) {
		context.set(Parser.class, parser);
		context.set(EmbeddedDocumentExtractor.class, new EmbedSpawner(document, context, embedOutput, handler));
	} else if (EmbedHandling.CONCATENATE == embedHandling) {
		context.set(Parser.class, parser);
		context.set(EmbeddedDocumentExtractor.class, new EmbedParser(document, context));
	} else {
		context.set(Parser.class, EmptyParser.INSTANCE);
		context.set(EmbeddedDocumentExtractor.class, new EmbedBlocker());
	}

	if (OutputFormat.HTML == outputFormat) {
		reader = new ParsingReader(parser, input, metadata, context, handler);
	} else {
		reader = new ParsingReader(parser, input, metadata, context);
	}

	return reader;
}
 
开发者ID:ICIJ,项目名称:extract,代码行数:66,代码来源:Extractor.java

示例7: Indexer

import org.apache.tika.parser.pdf.PDFParserConfig; //导入依赖的package包/类
public Indexer(String indexDir, boolean create, boolean fork, boolean ocr) throws IOException {
logger.entry();

this.fork = fork;

numErrors = 0;
numFiles = 0;

Directory dir = FSDirectory.open(Paths.get(indexDir));
Analyzer analyzer = new StandardAnalyzer();
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);

if (create) {
    iwc.setOpenMode(OpenMode.CREATE);
    logger.info("Configuration specified to create a new index or overwrites an existing one.");
} else {
    iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
    logger.info("Configuration specified to create a new index if one does not exist, otherwise the index will be opened and documents will be appended.");
}

writer = new IndexWriter(dir, iwc);

Parser autoDetectParser = new AutoDetectParser();
context = new ParseContext();

if (ocr) {
    TesseractOCRConfig ocrConfig = new TesseractOCRConfig();
    PDFParserConfig pdfConfig = new PDFParserConfig();
    pdfConfig.setExtractInlineImages(true);
    pdfConfig.setExtractUniqueInlineImagesOnly(false);
    context.set(Parser.class, autoDetectParser);
    context.set(TesseractOCRConfig.class, ocrConfig);
    context.set(PDFParserConfig.class, pdfConfig);
}

if (fork) {
    parser = new ForkParser(ForkParser.class.getClassLoader(), autoDetectParser);
} else {
    parser = autoDetectParser;
}

logger.exit();
   }
 
开发者ID:giuseppetotaro,项目名称:lucene-ir-engine,代码行数:44,代码来源:Indexer.java

示例8: fillPdfOptions

import org.apache.tika.parser.pdf.PDFParserConfig; //导入依赖的package包/类
private static void fillPdfOptions(PDFParserConfig pdfParserConfig, Map<String, Object> options) {
	final Object averageCharTolerance = options.get("pdfAverageCharTolerance");
	final Object enableAutoSpace = options.get("pdfEnableAutoSpace");
	final Object extractAcroFormContent = options.get("pdfExtractAcroFormContent");
	final Object extractAnnotationText = options.get("pdfExtractAnnotationText");
	final Object extractInlineImages = options.get("pdfExtractInlineImages");
	final Object extractUniqueInlineImagesOnly = options.get("pdfExtractUniqueInlineImagesOnly");
	final Object sortByPosition = options.get("pdfSortByPosition");
	final Object spacingTolerance = options.get("pdfSpacingTolerance");
	final Object suppressDuplicateOverlappingText = options.get("pdfSuppressDuplicateOverlappingText");

	if (averageCharTolerance != null) {
		pdfParserConfig.setAverageCharTolerance(Float.parseFloat(averageCharTolerance.toString()));
	}

	if (enableAutoSpace != null) {
		pdfParserConfig.setEnableAutoSpace((Boolean) enableAutoSpace);
	}

	if (extractAcroFormContent != null) {
		pdfParserConfig.setExtractAcroFormContent((Boolean) extractAcroFormContent);
	}

	if (extractAnnotationText != null) {
		pdfParserConfig.setExtractAnnotationText((Boolean) extractAnnotationText);
	}

	if (extractInlineImages != null) {
		pdfParserConfig.setExtractInlineImages((Boolean) extractInlineImages);
	} else {
		pdfParserConfig.setExtractInlineImages(true);
	}

	if (extractUniqueInlineImagesOnly != null) {
		pdfParserConfig.setExtractUniqueInlineImagesOnly((Boolean) extractUniqueInlineImagesOnly);
	}

	if (sortByPosition != null) {
		pdfParserConfig.setSortByPosition((Boolean) sortByPosition);
	}

	if (spacingTolerance != null) {
		pdfParserConfig.setSpacingTolerance(Float.parseFloat(spacingTolerance.toString()));
	}

	if (suppressDuplicateOverlappingText != null) {
		pdfParserConfig.setSuppressDuplicateOverlappingText((Boolean) suppressDuplicateOverlappingText);
	}
}
 
开发者ID:ICIJ,项目名称:node-tika,代码行数:50,代码来源:NodeTika.java

示例9: setPdfParserConfig

import org.apache.tika.parser.pdf.PDFParserConfig; //导入依赖的package包/类
/**
 * Sets the PDFParserConfig for inclusion in the ParseContext sent to the PDFBox parser,
 * useful for setting config like spacingTolerance.
 * 
 * @param pdfParserConfig
 */
public void setPdfParserConfig(PDFParserConfig pdfParserConfig)
{
    this.pdfParserConfig = pdfParserConfig;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:11,代码来源:PdfBoxContentTransformer.java


注:本文中的org.apache.tika.parser.pdf.PDFParserConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。