Использование PDFBox и FontBox.
public String readPDFInURL() throws EmptyFileException, IOException {
WebDriver driver = new FirefoxDriver();
// page with example pdf document
driver.get("file:///C:/Users/admin/Downloads/dotnet_TheRaceforEmpires.pdf");
URL url = new URL(driver.getCurrentUrl());
InputStream is = url.openStream();
BufferedInputStream fileToParse = new BufferedInputStream(is);
PDDocument document = null;
try {
document = PDDocument.load(fileToParse);
String output = new PDFTextStripper().getText(document);
} finally {
if (document != null) {
document.close();
}
fileToParse.close();
is.close();
}
return output;
}
Поскольку некоторые из функций из старых версий PDFBox устарели, мы должны использовать другой FontBox вместе с PDFBox. Я использовал PDFBox (2.0.3) и FontBox (2.0.3), и он отлично работает. Однако он не будет читать изображения.
чтение содержимого из PDF с помощью селена не будет работать. Загрузите файл pdf и прочитайте файл с помощью PDFbox или любой другой библиотеки. – metar