我正在使用iText java TextExtraction从PDF文件中读取文本。我使用下面的代码和它正常工作PDF的英文现在我有PDF包含数据作为图像。我想从该图像读取数据从PDF中的图像读取数据
public class pdfreader {
public static void main(String[] args) throws IOException, DocumentException, TransformerException {
String SRC = "";
String DEST = "";
for (String s : args) {
SRC = args[0];
DEST = args[1];
}
File file = new File(DEST);
file.getParentFile().mkdirs();
new pdfreader().readText(SRC, DEST);
}
public void readText(String src, String dest) throws IOException, DocumentException, TransformerException {
try {
PdfReader pdfReader = new PdfReader(src);
PdfReaderContentParser PdfParser = new PdfReaderContentParser(
pdfReader);
PrintWriter out = new PrintWriter(new FileOutputStream(
dest));
TextExtractionStrategy textStrategy;
for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
textStrategy = PdfParser.processContent(i,
new SimpleTextExtractionStrategy());
out.println(textStrategy.getResultantText());
}
out.flush();
out.close();
pdfReader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
我可以使用iText从PDF中提取图像吗 – hrishi
是的,您可以使用iText从PDF中提取图像,然后将图像提供给Tessaract,但这不是您的问题。 –
我正在考虑首先提取图像,然后从图像中读取数据 – hrishi