2016-01-21 70 views
0

我想使用TestNG和PDFBox驗證PDF文檔。PDF解析器文本包含

我想問,是PDF能夠檢查包含文字是這樣的:

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

回答

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

+0

它的工作原理,謝謝 –