【问题标题】:PDF parser text containsPDF解析器文本包含
【发布时间】:2016-01-21 07:37:52
【问题描述】:

我想使用 TestNG 和 PDFBox 验证 PDF 文档。

我想问一下,PDF 是否能够检查包含这样的文本:

PDFParser parser =  new PDFParser(stream);
parser.getDocument().conntains("ABC")

【问题讨论】:

    标签: java selenium-webdriver pdfbox


    【解决方案1】:

    试试下面的代码:-

      public void ReadPDF() throws Exception {
        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());
    
        Assert.assertTrue(TestText.contains("Open the setting.xml, you can see it is like this"));
    
        }
    

    下载库:- https://pdfbox.apache.org/index.html

    【讨论】:

      猜你喜欢
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      • 2013-02-06
      • 1970-01-01
      • 2020-05-12
      相关资源
      最近更新 更多