Hi there,
I am a new user for spire.pdf.
I used the following code to extract text data from pdf
import com.spire.pdf.*;
import com.spire.pdf.PdfPageBase;
import java.io.*;
public class Extract_Text {
public static void main(String[] args) throws IOException {
String input="1-s2.0-S187705092030750X-main.pdf";
//Load the PDF file
PdfDocument doc = new PdfDocument();
doc.loadFromFile(input);
//Create a new txt file to save the extracted text
String result = "output/extractAllText.txt";
File file=new File(result);
if(!file.exists()){
file.delete();
}
file.createNewFile();
FileWriter fw=new FileWriter(file,true);
BufferedWriter bw=new BufferedWriter(fw);
//Extract text from all the pages on the PDF
PdfPageBase page;
for(int i=0;i<doc.getPages().getCount();i++){
page=doc.getPages().get(i);
String text = page.extractText(true);
bw.write(text);
}
bw.flush();
bw.close();
fw.close();
}
}
But the following error has occured
Exception in thread "main" class com.spire.pdf.packages.sprfhc: Value cannot be null.
Parameter name: File doesn't exist
Parameter name: filename