我有一个名为example1.pdf的pdf 。
我想用line.let来读它,第一行是Hello my name is jhon
。所以我想用一个名为line
的字符串。我正在使用PDFTextStripper
和pdfBox进行尝试,但没有找到任何方法。任何帮助都将不胜感激。
发布于 2019-01-22 07:30:34
这种方法容易得多。
public static void main(String[] args) throws Exception, IOException
{
File file = new File("File.pdf");
PDDocument document = PDDocument.load(file);
PDFTextStripper pdfStripper = new PDFTextStripper();
pdfStripper.setStartPage(1);
pdfStripper.setEndPage(1);
//load all lines into a string
String pages = pdfStripper.getText(document);
//split by detecting newline
String[] lines = pages.split("\r\n|\r|\n");
int count=1; //Just to indicate line number
for(String temp:lines)
{
System.out.println(count+" "+temp);
count++;
}
}
https://stackoverflow.com/questions/45167592
复制相似问题