• java集成友宏转换服务奖pdf office转换为ofd以及ofd ocr识别


    第一步:集成友宏提供的jar包

      在配置好maven环境变量的前提下,通过命令:

    mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>,将jar包加入到maven仓库中。

      其中:

      <path-to-file>为你jar包所在的路径(尽量简单并且不要含中文)
      <group-id>为grouId号,与<artifact-id>组成唯一识别你jar包的坐标,当不在公共资源jar包中,自己自定义的jar时,可以自定义groupId号
      <artifact-id>为artifactId号,与<group-id>组成唯一识别你jar包的坐标,当不在公共资源jar包中,自己自定义的jar时,可以自定义artifactId号
      <version>jar包版本号,也可以自定义
      <packaging>包的后缀,一般都是jar

      例如:mvn install:install-file -Dfile=D:\agent-1.0.0.jar -DgroupId=com.youhong -DartifactId=agent -Dversion=1.0.0 -Dpackaging=jar
      导入jar包后,在pom文件添加依赖,导入此jar包。

    第二步:启动友宏提供的转换服务

      启动友宏提供的SC-OFDSuite-2.0.jar包,运行友宏提供的start.bat脚本即可启动。

      首次启动时不会成功,会在dos窗口打印机器码,将机器码发送给友宏的人员,友宏会根据机器码发送给我方一个许可文件license.lic。将此文件放入SC-OFDSuite-2.0.jar同级目录的config目录下。此时再次启动,成功。

    第三步:编码

      1:ofd内容识别

      //创建转换服务的连接

      final HTTPAgent agent = new HTTPAgent("http://转换服务的ip/转换服务的端口/v1/");

      //获取ocr文件中的文字

      FIle file = new FIle("要获取内容的文件地址");

      agent.getOcrText(file);

      2:ofd转换为ofice(包含Word,Excel,txt),html,图片

      private void transform(String filePath){

        boolean flag = true;

        if(filePath.contains("/")){

          flag = false;

        }

        String[] filePathArray = null;

        if(flag){

          filePathArray = filePath.split("\\\\");

        }else{

          filePathArray = filePath.split("/")

        }

        String newFIlePath = "";

        for(int i=0;i<filePathArray.length;i++){

          if(i<filePathArray.length - 1){

            if(flag){

              newFilePath += filePathArray[i]+"\\\\";

            }else{

              newFIlePath += filePathArray[i]+"/";

            }

          }else{

            Sring newFileName = filePathArray[i].split("\\.")[0]+".ofd";

            newFilePath += newFileName;

          }

        }

        //获取源文件格式

        String fileType = filePath.split("\\.")[1];

        final HTTPAgent httpAgent = new HTTPAgent("http://转换服务的ip/转换服务的端口/v1/");

        FIle srcFile = new File(filePath);

        FileOutputStream fileOupputStream = null;

        try{

          fileOutputStream = new FileOutputStream(newFIlePath);

          //office转换ofd

          if(PublicConstant.officeTypeList.contains(fileType)){

            httpAgent.officeToOFD(srcFile,fileOutputStream);

          }

          //图片转ofd

          if(PublicConstant.picTypeList.contains(fileType)){

            List<File> fileList = new ArrayLIst<>();

            fileList.add(srcFile);

            httpAgent.imagesToDoubleLayerOFD(fileList,fileOutputStream,null,null);

          }

          //html转ofd

          if("html".equals(fileType)){

            httpAgent.htmlFileToOFD(srcFile,fileOutputStream);

          }

        }catch(Exception e){

          log.error("记录日志");

        }finally{

          try{

            httpAgent.close();

            fileOutputStream.close();

          }catch(IOException e){

            log.error("记录日志");

          }

        }

      }

  • 相关阅读:
    Go 实现一个简单的TCP服务端
    将博客搬至CSDN
    My solution for Git Client Error: Permission denied (publickey)
    The Key to final data
    Design Pattern
    Difference between TCP and UDP
    Oracle SQL自带函数整理
    Java JDBC Batch
    Javascript Date 判断输入日期是否正确
    Javascript 数字保留2位小数
  • 原文地址:https://www.cnblogs.com/zwbsoft/p/16326735.html
Copyright © 2020-2023  润新知