Java 使用PDF x&;编写Excel;y坐标值

Java 使用PDF x&;编写Excel;y坐标值,java,excel,pdfbox,Java,Excel,Pdfbox,我是这个java世界的新手。使用PDFBox PrintTextlocations,我可以使用下面的代码从PDF文件中读取x&y坐标值 public class PrintTextLocations extends PDFTextStripper { public PrintTextLocations() throws IOException { super.setSortByPosition(true); } public static void main(String[] args

我是这个java世界的新手。使用PDFBox PrintTextlocations,我可以使用下面的代码从PDF文件中读取x&y坐标值

public class PrintTextLocations extends PDFTextStripper {

public PrintTextLocations() throws IOException {
    super.setSortByPosition(true);
}
public static void main(String[] args) throws Exception {

    PDDocument document = null;
    try {
        File input = new File("abcdef.pdf");
        document = PDDocument.load(input);
        if (document.isEncrypted()) {
            document.decrypt("");
        }
        PrintTextLocations printer = new PrintTextLocations();
        List allPages = document.getDocumentCatalog().getAllPages();
        for (int i = 0; i < allPages.size(); i++) {
            PDPage page = (PDPage) allPages.get(i);
            System.out.println("Processing page: " + i);
            PDStream contents = page.getContents();
            if (contents != null) {
                printer.processStream(page, page.findResources(), page.getContents().getStream());
            }
        }
    } finally {
        if (document != null) {
            document.close();
        }
    }
}
@Override 
protected void processTextPosition(TextPosition text) {
    System.out.println("String[X:" + text.getXDirAdj() +  ", Y:"  + text.getYDirAdj() + 
            " fs=" + text.getFontSize() + 
            " xscale=" + text.getXScale() + 
            " height=" + text.getHeightDir() + 
            " space="  + text.getWidthOfSpace() + 
            " width="  + text.getWidthDirAdj() + 
            "]" + text.getCharacter());
}
 }

我的问题是,如何使用上述x&y值将这些值写入Excel表格。我需要插入的确切位置根据PDF格式。请帮帮我。提前通知

是否可以使用上述x&Y坐标书写Excel表格…?Excel不用于在特定坐标下书写内容。使用图形格式,例如PDF。但是说真的-也许告诉你真正想做什么。这是一句老话“我想将PDF表格(如发票)转换为excel表格”吗?嗯,与此类似。只是我需要在excel表格中保留pdf格式。所以我尝试通过x&y坐标。这是可能的,你可以指导与适当的链接或片段我。除非你使用启发法,否则你不能。有可能用上面的x&Y坐标来写Excel表格吗…?Excel不适合在特定坐标下写东西。使用图形格式,例如PDF。但是说真的-也许告诉你真正想做什么。这是一句老话“我想将PDF表格(如发票)转换为excel表格”吗?嗯,与此类似。只是我需要在excel表格中保留pdf格式。所以我尝试通过x&y坐标。这是可能的,你可以指导与适当的链接或片段我。除非你使用启发式,否则你不能。
Processing page: 0
String[X:453.9598, Y:155.16022 fs=13.92 xscale=13.89324 height=10.523516 space=3.8623211 width=9.266785]S
String[X:463.19983, Y:155.16022 fs=13.92 xscale=13.89324 height=7.7951965 space=3.8623211 width=7.72464]a
String[X:470.99982, Y:155.16022 fs=13.92 xscale=13.89324 height=9.994557 space=3.8623211 width=3.8623352]l
String[X:474.8398, Y:155.16022 fs=13.92 xscale=13.89324 height=7.7951965 space=3.8623211 width=7.72464]e
String[X:482.63977, Y:155.16022 fs=13.92 xscale=13.89324 height=7.7951965 space=3.8623211 width=7.72464]s
String[X:490.43976, Y:155.16022 fs=13.92 xscale=13.89324 height=0.0 space=3.8623211 width=3.8623352] 
String[X:494.27975, Y:155.16022 fs=13.92 xscale=13.89324 height=1.8095994 space=3.8623211 width=4.6264343]-
String[X:498.95978, Y:155.16022 fs=13.92 xscale=13.89324 height=0.0 space=3.8623211 width=3.8623352]