Reading a particular page from a PDF document using PDFBox

后端 未结 6 2034
醉话见心
醉话见心 2020-12-03 10:41

How do I read a particular page (given a page number) from a PDF document using PDFBox?

6条回答
  •  情深已故
    2020-12-03 11:03

    Here is the solution. Hope it will solve your issue.

    string fileName="C:\mypdf.pdf";
    PDDocument doc = PDDocument.load(fileName);                   
    PDFTextStripper stripper = new PDFTextStripper();
    stripper.setStartPage(1);
    stripper.setEndPage(2);
    //above page number 1 to 2 will be parsed. for parsing only one page set both value same (ex:setStartPage(1);  setEndPage(1);)
    string reslut = stripper.getText(doc);
    
    doc.close();
    

提交回复
热议问题