使用PDFBox提取pdf内文本坐标及字体信息
实现代码,仅供参考
private static void GetTextInfo(String str) throws Exception {
File file = new File(str);
PDDocument doc = PDDocument.load(file);
List<String> tmpList = new ArrayList<>();
PDFTextStripper stripper = new PDFTextStripper() {
@Override
protected void writeString(String text, List<TextPosition> textPositions) throws IOException {
super.writeString(text, textPositions);
for (int i = 0; i < textPositions.size(); i++) {
TextPosition tp = textPositions.get(i);
tmpList.add(tp.getUnicode() + " x:" + tp.getX() + " y:" + tp.getY() + " size:" + tp.getWidth()
+ " font:" + tp.getFont().getName());
}
}
};
stripper.getText(doc);
for (int i = 0; i < tmpList.size(); i++) {
System.out.println(tmpList.get(i));
}
}
使用PDFBox 将pdf中的注释追加到另外的pdf中
private static void AddInk(String str1, String str2) {
PDDocument pdf1 = null;
PDDocu