• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TextExtractionStrategy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getPdfContent

import com.itextpdf.text.pdf.parser.TextExtractionStrategy; //导入依赖的package包/类
private String getPdfContent(String pdfFile) {
	try {
		PdfReader reader = new PdfReader(pdfFile);
		StringBuffer sb = new StringBuffer();
		PdfReaderContentParser parser = new PdfReaderContentParser(reader);
		TextExtractionStrategy strategy;
		for (int i = 1; i <= reader.getNumberOfPages(); i++) {
			strategy = parser.processContent(i, new SimpleTextExtractionStrategy());
			sb.append(strategy.getResultantText());
		}
		reader.close();
		return sb.toString();
	} catch (IOException e) {
		throw new IllegalArgumentException("Not able to read file " + pdfFile, e);
	}
}
 
开发者ID:sjcdigital,项目名称:presenca-vereadores-sjc,代码行数:17,代码来源:PDFAttendanceParser.java


示例2: extractAndStore

import com.itextpdf.text.pdf.parser.TextExtractionStrategy; //导入依赖的package包/类
<E extends TextExtractionStrategy> String extractAndStore(PdfReader reader, String format, Class<E> strategyClass, RenderFilter... filters) throws Exception
{
    StringBuilder builder = new StringBuilder();

    for (int page = 1; page <= reader.getNumberOfPages(); page++)
    {
        TextExtractionStrategy strategy = strategyClass.getConstructor().newInstance();
        if (filters != null && filters.length > 0)
        {
            strategy = new FilteredTextRenderListener(strategy, filters);
        }
        String pageText = extract(reader, page, strategy);
        Files.write(Paths.get(String.format(format, page)), pageText.getBytes("UTF8"));

        if (page > 1)
            builder.append("\n\n");
        builder.append(pageText);
    }

    return builder.toString();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:22,代码来源:TextExtraction.java


示例3: extractsPdfLines

import com.itextpdf.text.pdf.parser.TextExtractionStrategy; //导入依赖的package包/类
public static String[] extractsPdfLines(String PdfFile) throws IOException {
	try {
		StringBuffer buff = new StringBuffer();
		String ExtractedText = null;
		PdfReader reader = new PdfReader(PdfFile);
		PdfReaderContentParser parser = new PdfReaderContentParser(reader);
		TextExtractionStrategy strategy;

		for (int i = 1; i <= reader.getNumberOfPages(); i++) {
			strategy = parser.processContent(i, new SimpleTextExtractionStrategy());
			ExtractedText = strategy.getResultantText().toString();
			buff.append(ExtractedText + "\n");
		}

		String[] LinesArray;
		LinesArray = buff.toString().split("\n");
		reader.close();
		return LinesArray;
	} catch (Exception e) {
		return null;
	}
}
 
开发者ID:friesey,项目名称:preservation-tools,代码行数:23,代码来源:PdfAnalysis.java


示例4: getTextChunks

import com.itextpdf.text.pdf.parser.TextExtractionStrategy; //导入依赖的package包/类
private static List<LocationTextExtractionStrategy.TextChunk> getTextChunks() throws IOException {
    PdfReader reader = new PdfReader(RESOURCES_DIR + "KLEE.pdf");
    PdfReaderContentParser parser = new PdfReaderContentParser(reader);
    PrintWriter out = new PrintWriter(new FileOutputStream(RESOURCES_DIR + "extracted text"));
    TextExtractionStrategy strategy;
    for (int i = 1; i <= reader.getNumberOfPages(); i++) {
        strategy
                = parser.processContent(i, new LocationTextExtractionStrategy());
        out.println(strategy.getResultantText());
    }
    out.flush();
    out.close();
    return null;
}
 
开发者ID:mrniket,项目名称:pdftagger,代码行数:15,代码来源:Main.java


示例5: open

import com.itextpdf.text.pdf.parser.TextExtractionStrategy; //导入依赖的package包/类
@Override
public BookReadingResult open(@NonNull File file, @NonNull PercentSender percentSender, @NonNull Runnable readingEndSender) {

    try {
        PdfReader pdfReader = new PdfReader(file.getAbsolutePath());
        PdfReaderContentParser parser = new PdfReaderContentParser(pdfReader);
        int numberOfPages = pdfReader.getNumberOfPages();
        int oldPercent = 0, newPercent;

        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
            TextExtractionStrategy strategy = parser.processContent(i, new SimpleTextExtractionStrategy());
            String pageText = strategy.getResultantText();

            stringBuffer.append(pageText);

            if (pageText.endsWith("\\.") ||
                    pageText.endsWith("!") ||
                    pageText.endsWith("?") ||
                    pageText.endsWith(":")) {
                stringBuffer.append(" ");
            } else {
                stringBuffer.append(". ");
            }

            newPercent = 100 * i / numberOfPages;
            if (newPercent != oldPercent) {
                percentSender.refreshPercents(oldPercent, newPercent);
                oldPercent = newPercent;
            }
        }

        pdfReader.close();

        String resultText = new String(stringBuffer);
        resultText = resultText.trim();                         // delete first and last space (if exist)
        resultText = resultText.replaceAll("\\s+", " ");        // delete all duplicate white spaces
        resultText = resultText.replaceAll("(\\.)+", "\\.");        // delete all duplicate dots

        if (resultText.length() < 1) {
            return null;
        }

        readingEndSender.run();
        return new BookReadingResult(resultText, InternalStorageFileHelper.fileNameWithoutExtension(file), "");

    } catch (IOException e) {
        e.printStackTrace();

        return null;
    }

}
 
开发者ID:pashkobohdan,项目名称:FastReading,代码行数:54,代码来源:PdfFileOpener.java


示例6: RemappingExtractionFilter

import com.itextpdf.text.pdf.parser.TextExtractionStrategy; //导入依赖的package包/类
public RemappingExtractionFilter(TextExtractionStrategy strategy) throws NoSuchFieldException, SecurityException
{
    this.strategy = strategy;
    this.stringField = TextRenderInfo.class.getDeclaredField("text");
    this.stringField.setAccessible(true);
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:7,代码来源:RemappingExtractionFilter.java


示例7: extract

import com.itextpdf.text.pdf.parser.TextExtractionStrategy; //导入依赖的package包/类
String extract(PdfReader reader, int pageNo, TextExtractionStrategy strategy) throws IOException
{
    return PdfTextExtractor.getTextFromPage(reader, pageNo, strategy);
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:5,代码来源:TextExtraction.java


示例8: extractRemapped

import com.itextpdf.text.pdf.parser.TextExtractionStrategy; //导入依赖的package包/类
String extractRemapped(PdfReader reader, int pageNo) throws IOException, NoSuchFieldException, SecurityException
{
    TextExtractionStrategy strategy = new RemappingExtractionFilter(new LocationTextExtractionStrategy());
    return PdfTextExtractor.getTextFromPage(reader, pageNo, strategy);
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:6,代码来源:RemappedExtraction.java


示例9: searchforStringinPdfFiles

import com.itextpdf.text.pdf.parser.TextExtractionStrategy; //导入依赖的package包/类
public static void searchforStringinPdfFiles(File file) throws IOException {

		outputfile.println("<Dateiname>" + (file.getName()) + "</Dateiname>");

		int trefferinDatei;

		if (filetools.pdf.PdfAnalysis.testPdfOk(file)) {
			try {
				PdfReader reader = new PdfReader(file.toString());
				int pagesPdf = reader.getNumberOfPages();
				StringBuffer buff = new StringBuffer();
				String ExtractedText = null;
				PdfReaderContentParser parser = new PdfReaderContentParser(reader);
				TextExtractionStrategy strategy;

				trefferinDatei = 0;
				for (int i = 1; i <= pagesPdf; i++) {
					strategy = parser.processContent(i, new SimpleTextExtractionStrategy());
					ExtractedText = strategy.getResultantText().toString();
					buff.append(ExtractedText + "\n");
					String[] LinesArray = buff.toString().split("\n");
					int linesPdf = LinesArray.length;

					for (int j = 0; (j < linesPdf && (stringfound < MAXIMAL_HITS)); j++) {
						String paragraph = LinesArray[j].toLowerCase();
						String searchStringlowerCase = searchedString.toLowerCase();
						if (paragraph.contains(searchStringlowerCase)) {
							trefferinDatei++;
							stringfound++;
							outputfile.println("<Seitenzahl>" + i + "</Seitenzahl>");
							outputfile.println("<GanzeZeile>" + (LinesArray[j]) + "</GanzeZeile>");
						}
					}

				}
				outputfile.println("<TextinDatei>" + trefferinDatei + "</TextinDatei>");
				outputfile.println("<Suchergebnis>" + trefferinDatei + " x " + "</Suchergebnis>");

				reader.close();

			} catch (Exception e) {
				outputfile.println("<Fehlermeldung>" + e + "</Fehlermeldung>");
			}
		}

	}
 
开发者ID:friesey,项目名称:preservation-tools,代码行数:47,代码来源:TextSucheInOrdner.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AuthUtils类代码示例发布时间:2022-05-22
下一篇:
Java ServerCallStreamObserver类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap