阅读硒中的PDF:构造函数PDFParser(BufferedInputStream)未定义 [英] Read PDF in selenium: The constructor PDFParser(BufferedInputStream) is undefined

查看:251
本文介绍了阅读硒中的PDF:构造函数PDFParser(BufferedInputStream)未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到错误

构造函数PDFParser(BufferedInputStream)未定义

The constructor PDFParser(BufferedInputStream) is undefined

我正在尝试使用Selenium读取PDF内容.

I am trying to read PDF contents using Selenium.

WebDriver driver=new FirefoxDriver();
driver.get("http://www.axmag.com/download/pdfurl-guide.pdf");
URL TestURL = new URL("http://www.axmag.com/download/pdfurl-guide.pdf");
BufferedInputStream TestFile = new BufferedInputStream(TestURL.openStream());
PDFParser TestPDF = new PDFParser(TestFile);
TestPDF.parse();
String TestText = new PDFTextStripper().getText(TestPDF.getPDDocument());
System.out.println(TestText);
Assert.assertTrue(TestText.contains("Open the setting.xml, you can see it is like this"));

任何人都可以帮忙吗?

推荐答案

我遇到了同样的问题.该问题是由于使用(Apache PDFBox 2.0.0 API)jar文件所致. 从构建路径中删除它们,并使用(Apache PDFBox 1.8.11 API),因为2.0中的PDFParser类没有PDFParser(BufferedInputStream args)构造函数.但是1.8具有PDFParser(InputStream args)构造函数.因此它将完全解决您的问题.

I got the same Propblem you have faced. The problem is due to using (Apache PDFBox 2.0.0 API) jar Files. Remove them from build path and use (Apache PDFBox 1.8.11 API) as PDFParser class in 2.0 doesn't have PDFParser(BufferedInputStream args) Constructor. But 1.8 has PDFParser(InputStream args) Constructor. So it will Definately Solve your Problem.

我还将分享我的代码.如果您需要帮助,可以从中获取帮助.

I will also share my code. if you need Help you can take from that.

InputStream is = new FileInputStream(getLatestFile);
        PDFParser parser = new PDFParser(is);
        parser.parse();
        String output=new PDFTextStripper().getText(parser.getPDDocument());
        System.out.println(output);
        parser.getPDDocument().close(); 

这篇关于阅读硒中的PDF:构造函数PDFParser(BufferedInputStream)未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆