java项目处理OFD文件
一、导入 jar 依赖包
1.1 Maven 项目引入 jar 包
<dependency> <groupId>org.ofdrw</groupId> <artifactId>ofdrw-converter</artifactId> <version>2.0.2</version> </dependency>
二、实现思路
1、直接解析ofd获取其内容,在此不多述
2、走OCR识别
1)ofd转pdf,pdf再转图片,图片走OCR识别
Path ofdPath = Paths.get("D:/ofd/1.ofd"); Path pdfPath = Paths.get("D:/ofd/target/1.pdf"); try (OFDExporter exporter = new PDFExporterPDFBox(ofdPath, pdfPath)) { exporter.export(); } catch (IOException e) { e.printStackTrace(); }
结论:出现了下述的重影问题,转PDF效果太差。所以该方案取消
2)ofd转图片,图片走OCR识别
Path ofdPath = Paths.get("D:/ofd/1.ofd"); Path imgPath = Paths.get("D:/ofd/img"); try (ImageExporter exporter = new ImageExporter(ofdPath, imgPath, "PNG", 20d)) { exporter.export(); } catch (IOException e) { e.printStackTrace(); }
结论:测试了多个ofd文件,转换图片效果较好