How can I extract specific information from a pdf file and save it as a table in a xlsx file? For example, I want to take specific information from a report of a company like the release date of the file, the revenue, the loss of profit and the financial gain and update it regularly in the same xlsx table.
This is from another question from here, but I don't know what to add and if it reaches my expectations.
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.text.PDFTextStripperByArea;
public class ExtractText {
// Usage: xxx.jar filepath page x y width height
public static void main(String[] args) throws IOException {
if (args.length != 6) {
System.out.println("Help info");
return;
}
// Parameters
String filepath = args[0];
int page = Integer.parseInt(args[1]);
int x = Integer.parseInt(args[2]);
int y = Integer.parseInt(args[3]);
int width = Integer.parseInt(args[4]);
int height = Integer.parseInt(args[5]);
PDDocument document = PDDocument.load(new File(filepath));
PDFTextStripperByArea textStripper = new PDFTextStripperByArea();
Rectangle2D rect = new java.awt.geom.Rectangle2D.Float(x, y, width, height);
textStripper.addRegion("region", rect);
PDPage docPage = document.getPage(page);
textStripper.extractRegions(docPage);
String textForRegion = textStripper.getTextForRegion("region");
System.out.println(textForRegion);
}
}