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


Java SimpleTextExtractionStrategy类代码示例

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


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

示例1: getPdfContent

import com.itextpdf.text.pdf.parser.SimpleTextExtractionStrategy; //导入依赖的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: extractsPdfLines

import com.itextpdf.text.pdf.parser.SimpleTextExtractionStrategy; //导入依赖的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

示例3: extractSimple

import com.itextpdf.text.pdf.parser.SimpleTextExtractionStrategy; //导入依赖的package包/类
String extractSimple(PdfReader reader, int pageNo) throws IOException
{
    return PdfTextExtractor.getTextFromPage(reader, pageNo, new SimpleTextExtractionStrategy()
    {
        boolean empty = true;

        @Override
        public void beginTextBlock()
        {
            if (!empty)
                appendTextChunk("<BLOCK>");
            super.beginTextBlock();
        }

        @Override
        public void endTextBlock()
        {
            if (!empty)
                appendTextChunk("</BLOCK>\n");
            super.endTextBlock();
        }

        @Override
        public String getResultantText()
        {
            if (empty)
                return super.getResultantText();
            else
                return "<BLOCK>" + super.getResultantText();
        }

        @Override
        public void renderText(TextRenderInfo renderInfo)
        {
            empty = false;
            super.renderText(renderInfo);
        }
        
    });
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:41,代码来源:TextExtraction.java

示例4: open

import com.itextpdf.text.pdf.parser.SimpleTextExtractionStrategy; //导入依赖的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

示例5: searchforStringinPdfFiles

import com.itextpdf.text.pdf.parser.SimpleTextExtractionStrategy; //导入依赖的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.SimpleTextExtractionStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。