第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用java將PDF轉(zhuǎn)換為CSV

使用java將PDF轉(zhuǎn)換為CSV

牛魔王的故事 2022-06-04 17:26:12
我已經(jīng)嘗試了堆棧溢出和外部的大部分內(nèi)容問(wèn)題:我有一個(gè)包含內(nèi)容和表格的 pdf。我還需要解析表格和內(nèi)容。APIs: https ://github.com/tabulapdf/tabula-java 我正在使用tabula-java它忽略了一些內(nèi)容,并且表格單元格內(nèi)的內(nèi)容沒(méi)有以正確的方式分離。我的 PDF 有這樣的內(nèi)容 DATE :1/1/2018         ABCD                   SCODE:FFFT                       --ACCEPTED--    USER:ADMIN         BATCH:RR               EEE    CON BATCH    =======================================================================    MAIN SNO SUB  VALUE DIS %    R    12   rr1 0125  24.5            SLNO  DESC  QTY  TOTAL  CODE   FREE            1     ABD   12   90     BBNEW  -NILL-            2     XDF   45   55     GHT55  MRP            3     QWE   08   77     CAT    -NILL-    =======================================================================    MAIN SNO SUB  VALUE DIS %    QW    14   rr2 0122  24.5            SLNO  DESC  QTY  TOTAL  CODE   FREE            1     ABD   12   90     BBNEW  -NILL-            2     XDF   45   55     GHT55  MRP            3     QWE   08   77     CAT    -NILL-要轉(zhuǎn)換的表格代碼:public static void toCsv() throws ParseException {        String commandLineOptions[] = { "-p", "1", "-o", "$csv", };        CommandLineParser parser = new DefaultParser();        try {            CommandLine line = parser.parse(TabulaUtil.buildOptions(), commandLineOptions);            new TabulaUtil(System.out, line).extractFileInto(                    new File("/home/sample/firstPage.pdf"),                    new File("/home/sample/onePage.csv"));        } catch (Exception e) {            e.printStackTrace();        }    }tabula 甚至支持命令行界面java -jar TabulaJar/tabula-1.0.2-jar-with-dependencies.jar -p all  -o  $csv -b Pdfs我嘗試使用-c,--columns <COLUMNS>表格,它通過(guò)列邊界的 X 坐標(biāo)獲取單元格但問(wèn)題是我的 pdfs 內(nèi)容是動(dòng)態(tài)的。即表大小已更改。堆棧溢出中的這些鏈接和更多的力對(duì)我有用。
查看完整描述

2 回答

?
守著一只汪

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊

Apache基金會(huì)的項(xiàng)目很少

Tikka 支持廣泛的擴(kuò)展,包括 pdf、ppt、xls。https://tika.apache.org/1.24.1/formats.html中提到了支持的格式

https://tika.apache.org/

PDF Box - 特定于 pdf 相關(guān)功能

https://pdfbox.apache.org/


查看完整回答
反對(duì) 回復(fù) 2022-06-04
?
眼眸繁星

TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個(gè)贊

在此處查看使用 Java 將 PDF 提取為 CSV 的任何示例:https ://github.com/pdftables/java-pdftables-api 。每個(gè)頁(yè)面都是獨(dú)立考慮的,因此您的 PDF 的動(dòng)態(tài)特性不應(yīng)該成為問(wèn)題。您可以在他們的網(wǎng)站上使用免費(fèi)試用版。


package com.pdftables.examples;


import java.io.File;

import java.util.Arrays;

import java.util.List;


import org.apache.commons.io.FileUtils;

import org.apache.http.HttpEntity;

import org.apache.http.client.config.CookieSpecs;

import org.apache.http.client.config.RequestConfig;

import org.apache.http.client.methods.CloseableHttpResponse;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.entity.mime.MultipartEntityBuilder;

import org.apache.http.entity.mime.content.FileBody;

import org.apache.http.impl.client.CloseableHttpClient;

import org.apache.http.impl.client.HttpClients;


public class ConvertToFile {

    private static List<String> formats = Arrays.asList(new String[] { "csv", "xml", "xlsx-single", "xlsx-multiple" });


    public static void main(String[] args) throws Exception {

        if (args.length != 3) {

            System.out.println("Command line: <API_KEY> <FORMAT> <PDF filename>");

            System.exit(1);

        }


        final String apiKey = args[0];

        final String format = args[1].toLowerCase();

        final String pdfFilename = args[2];


        if (!formats.contains(format)) {

            System.out.println("Invalid output format: \"" + format + "\"");

            System.exit(1);

        }


        // Avoid cookie warning with default cookie configuration

        RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();


        File inputFile = new File(pdfFilename);


        if (!inputFile.canRead()) {

            System.out.println("Can't read input PDF file: \"" + pdfFilename + "\"");

            System.exit(1);

        }


        try (CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(globalConfig).build()) {

            HttpPost httppost = new HttpPost("https://pdftables.com/api?format=" + format + "&key=" + apiKey);

            FileBody fileBody = new FileBody(inputFile);


            HttpEntity requestBody = MultipartEntityBuilder.create().addPart("f", fileBody).build();

            httppost.setEntity(requestBody);


            System.out.println("Sending request");


            try (CloseableHttpResponse response = httpclient.execute(httppost)) {

                if (response.getStatusLine().getStatusCode() != 200) {

                    System.out.println(response.getStatusLine());

                    System.exit(1);

                }

                HttpEntity resEntity = response.getEntity();

                if (resEntity != null) {

                    final String outputFilename = getOutputFilename(pdfFilename, format.replaceFirst("-.*$", ""));

                    System.out.println("Writing output to " + outputFilename);


                    final File outputFile = new File(outputFilename);

                    FileUtils.copyToFile(resEntity.getContent(), outputFile);

                } else {

                    System.out.println("Error: file missing from response");

                    System.exit(1);

                }

            }

        }

    }


    private static String getOutputFilename(String pdfFilename, String suffix) {

        if (pdfFilename.length() >= 5 && pdfFilename.toLowerCase().endsWith(".pdf")) {

            return pdfFilename.substring(0, pdfFilename.length() - 4) + "." + suffix;

        } else {

            return pdfFilename + "." + suffix;

        }

    }

}



查看完整回答
反對(duì) 回復(fù) 2022-06-04
  • 2 回答
  • 0 關(guān)注
  • 288 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)