繁体   English   中英

如何将 PDF 转换为 JSON/EXCEL/WORD 文件?

[英]How to convert a PDF to a JSON/EXCEL/WORD file?

我需要从 pdf 文件及其 header 中获取数据,以便进一步与 DB 数据进行比较

我尝试使用 pdfbox、google vision ocr、itext,但所有库都给了我一行没有结构和标题的信息。

示例:日期\n编号\n状态\n12\12\2020\n442334\已交付

我将尝试将 pdf 转换为 excel/word 并从中获取数据,但为了实现这一目标,我需要读取 pdf 并在 excel/word 中写入数据

如何获取带有标题的数据?

“Date\nNumber\nStatus\n12/12/2020\n442334\ndelivered”对我来说看起来很有条理。 您可以将其拆分为“\n”。 不过,这需要一些表结构的知识。

我在使用 Google Vision OCR 方面取得了很好的经验。 你怎么称呼它?

我没有找到我的问题的答案。

我将此代码用于我的任务:

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.text.PDFTextStripperByArea;
import java.awt.*;
import java.io.File;
import java.io.IOException;

public class ExtractTextByArea {

    public String getTextFromCoordinate(String filepath,int x,int y,int width,int height) {
        String result = "";
        try (PDDocument document = PDDocument.load(new File(filepath))) {

            if (!document.isEncrypted()) {

                PDFTextStripperByArea stripper = new PDFTextStripperByArea();
                stripper.setSortByPosition(true);
               // Rectangle rect = new Rectangle(260, 35, 70, 10);
                Rectangle rect = new Rectangle(x,y,width,height);
                stripper.addRegion("class1", rect);
                PDPage firstPage = document.getPage(0);
                stripper.extractRegions( firstPage );
               // System.out.println("Text in the area:" + rect);
                result = stripper.getTextForRegion("class1");

            }
        } catch (IOException e){
            System.err.println("Exception while trying to read pdf document - " + e);
        }
        return result;
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM