我正在尝试使用 PDFBox 从 pdf 文件中提取带有坐标的文本。
我混合了在互联网上找到的一些方法/信息(也是stackoverflow),但是我的坐标问题似乎不正确。例如,当我尝试使用坐标在 tex 顶部绘制矩形时,该矩形会在其他地方绘制。
这是我的代码(请不要判断风格,写得很快只是为了测试)
文本行.java
import java.util.List;
import org.apache.pdfbox.text.TextPosition;
/**
*
* @author samue
*/
public class TextLine {
public List<TextPosition> textPositions = null;
public String text = "";
}
Run Code Online (Sandbox Code Playgroud)
myStripper.java
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.pdfbox.text.TextPosition;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the …Run Code Online (Sandbox Code Playgroud)