簡體   English   中英

無法使用 selenium web 驅動程序讀取 pdf 文檔

[英]unable to read pdf document using selenium web driver

我正在編寫代碼以讀取 selenium 中的 pdf 文件,使用 Java ZBCD1B68617765B1DFCZFF04A 庫。 我把我的代碼寫成

    URL url = new URL(str);
    InputStream is=url.openStream();
    BufferedInputStream fileParse=new BufferedInputStream(is);
    PDDocument document=null;
    document=PDDocument.load(fileParse);
    String pdfContent=new PDFTextStripper().getText(document);

但是我在行 document=PDDocument.load(fileParse) 以及

    java.io.IOException: Error: End-of-File, expected line
    at org.apache.pdfbox.pdfparser.BaseParser.readLine(BaseParser.java:1119)
    at org.apache.pdfbox.pdfparser.COSParser.parseHeader(COSParser.java:2017)
    at org.apache.pdfbox.pdfparser.COSParser.parsePDFHeader(COSParser.java:1988)
    at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:269)
    at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1143)
    at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1040)

我需要驗證 pdf 文件上的內容。 感謝幫助。 謝謝

只需您可以使用下面的代碼行及其工作:

//Loading an existing document
 File file = new File("yourPdfFilepath");
 PDDocument document = PDDocument.load(file);
 //Instantiate PDFTextStripper class
 PDFTextStripper pdfStripper = new PDFTextStripper();
 //Retrieving text from PDF document
 String pdfcontent = pdfStripper.getText(document);

希望對你有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM