簡體   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