热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

基于ABBYYSDK实现java版本Hello功能!

1、ABBYY安装完成后这个目录下存放示例代码,C:\ProgramData\ABBYY\SDK\11\FineReaderEngine\Samples2、新建工程把

 

1、ABBYY安装完成后

    这个目录下存放示例代码,C:\ProgramData\ABBYY\SDK\11\FineReader Engine\Samples

2、新建工程把Hello 里面的代码和SamplesConfig.java 放入工程中

3、直接贴代码

SamplesConfig.java 用于存放序列号,本地安装路径等信息

package com.abbyy.test;// � 2013 ABBYY Production LLC
// SAMPLES code is property of ABBYY, exclusive rights are reserved.
//
// DEVELOPER is allowed to incorporate SAMPLES into his own APPLICATION and modify it under
// the terms of License Agreement between ABBYY and DEVELOPER.// Auto-generated config-file for FineReader Engine Java samplespublic class SamplesConfig {/*** Folder with FRE dll* 设置ABBYY所需dll文件地址*/public static String GetDllFolder() {if( is64BitJVMArchitecture() ) {return "C:\\Program Files\\ABBYY SDK\\11\\FineReader Engine\\Bin64";} else {return "C:\\Program Files\\ABBYY SDK\\11\\FineReader Engine\\Bin";}}/*** 设置 ABBYY所需 秘钥* Return developer serial number for FRE*/public static String GetDeveloperSN() {return "SWTT-1101-0006-5071-4505-1208"; //申请试用版序列号}/*** Return full path to Samples directory* 设置ABBYY转换后生成路径*/public static String GetSamplesFolder() {
// return "Directory\\where\\samples\\reside";return "D:\\zhjwFile\\05_abbyy";}/*** Determines whether the JVM architecture is a 64-bit architecture* 判断当前jdk 所属版本是64还是32*/private static boolean is64BitJVMArchitecture(){String jvmKeys [] = {"sun.arch.data.model", "com.ibm.vm.bitmode", "os.arch"};for( String key : jvmKeys ) {String property = System.getProperty( key );if( property != null ) {if( property.indexOf( "64" ) >= 0 ) {return true;} else if( property.indexOf( "32" ) >= 0 ) {return false;} else if( property.indexOf( "86" ) >= 0 ) {return false;}}}return false;}
}

Hello.java 单个文件的转换

package com.abbyy.test.Hello;import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;// (c) 2013 ABBYY Production LLC
// SAMPLES code is property of ABBYY, exclusive rights are reserved.
//
// DEVELOPER is allowed to incorporate SAMPLES into his own APPLICATION and modify it under
// the terms of License Agreement between ABBYY and DEVELOPER.// ABBYY FineReader Engine 11 Sample// This sample shows basic steps of ABBYY FineReader Engine usage:
// Initializing, opening image file, recognition and export.
import com.abbyy.FREngine.*;
import com.abbyy.test.SamplesConfig;public class Hello {public static void main(String[] args) {try {Hello application = new Hello();application.Run();} catch (Exception ex) {displayMessage(ex.getMessage());ex.printStackTrace();}}public void Run() throws Exception {// 加载ABBYY转换引擎loadEngine();try {// 使用ABBYY FineReader引擎进行处理processWithEngine();} finally {// 卸载ABBYY FineReader引擎unloadEngine();}}/*** 加载本地环境,创建转换引擎* @throws Exception*/private void loadEngine() throws Exception {displayMessage("初始化引擎…");engine = Engine.GetEngineObject(SamplesConfig.GetDllFolder(), SamplesConfig.GetDeveloperSN());}/*** 使用ABBYY FineReader引擎进行处理*/private void processWithEngine() {try {// 设置转换参数setupFREngine();// 转换样例图片processImage();} catch (Exception ex) {displayMessage(ex.getMessage());}}/*** 设置转换参数*/private void setupFREngine() {displayMessage("预定义的配置文件加载…");engine.LoadPredefinedProfile("Default");// Possible profile names are:// "DocumentConversion_Accuracy", 文档转换精度,// "DocumentConversion_Speed", 文档转换速度// "DocumentArchiving_Accuracy", 文档归档准确性// "DocumentArchiving_Speed", 文档归档的速度// "BookArchiving_Accuracy", 书存档准确性// "BookArchiving_Speed", 书存档速度// "TextExtraction_Accuracy", 文本提取的准确性// "TextExtraction_Speed", 文本提取的速度// "FieldLevelRecognition", 字段级识别// "BarcodeRecognition_Accuracy", 条形码识别精度// "BarcodeRecognition_Speed", 条形码识别速度// "HighCompressedImageOnlyPdf", 高度压缩图像Pdf// "BusinessCardsProcessing", 名片处理// "EngineeringDrawingsProcessing", 工程图纸处理// "Version9Compatibility", Version9兼容性// "Default" 默认}/*** 转换图片*/private void processImage() {String fileName = "Demo_ChinesePRC.tif"; //Demo_ChinesePRC.tifString imagePath = SamplesConfig.GetSamplesFolder() + "\\"+fileName;try {// Don't recognize PDF file with a textual content, just copy it// 不要识别带有文本内容的PDF文件,只需复制它if (engine.IsPdfWithTextualContent(imagePath, null)) {displayMessage("复制的结果……");String resultPath = SamplesConfig.GetSamplesFolder() + "\\"+fileName+".pdf";Files.copy(Paths.get(imagePath), Paths.get(resultPath), StandardCopyOption.REPLACE_EXISTING);return;}// 创建文档IFRDocument document = engine.CreateFRDocument();try {// Add image file to documentdisplayMessage("加载图片……");document.AddImageFile(imagePath, null, null);// Process documentdisplayMessage("过程……");// 创建识别器参数类IDocumentProcessingParams dpp = engine.CreateDocumentProcessingParams();IPageProcessingParams ppp = dpp.getPageProcessingParams();ppp.getRecognizerParams().SetPredefinedTextLanguage("ChinesePRC+English"); //设置语言为简体中文和英语document.Process(dpp);// Save resultsdisplayMessage("保存结果……");// 使用默认参数将结果保存到rtfString rtfExportPath = SamplesConfig.GetSamplesFolder() + "\\"+fileName+".rtf";document.Export(rtfExportPath, FileExportFormatEnum.FEF_RTF, null);// Save results to pdf using 'balanced' scenario// 使用“平衡”场景将结果保存为pdfIPDFExportParams pdfParams = engine.CreatePDFExportParams();pdfParams.setScenario(PDFExportScenarioEnum.PES_Balanced);String pdfExportPath = SamplesConfig.GetSamplesFolder() + "\\"+fileName+".pdf";document.Export(pdfExportPath, FileExportFormatEnum.FEF_PDF, pdfParams);} finally {// Close documentdocument.Close();}} catch (Exception ex) {displayMessage(ex.getMessage());}}/*** 卸载ABBYY FineReader引擎* @throws Exception*/private void unloadEngine() throws Exception {displayMessage("卸载ABBYY FineReader引擎...");engine = null;Engine.DeinitializeEngine();}private static void displayMessage(String message) {System.out.println(message);}private IEngine engine = null;
}

 


推荐阅读
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 关键词:Golang, Cookie, 跟踪位置, net/http/cookiejar, package main, golang.org/x/net/publicsuffix, io/ioutil, log, net/http, net/http/cookiejar ... [详细]
  • 个人学习使用:谨慎参考1Client类importcom.thoughtworks.gauge.Step;importcom.thoughtworks.gauge.T ... [详细]
  • 本文详细介绍了Java中vector的使用方法和相关知识,包括vector类的功能、构造方法和使用注意事项。通过使用vector类,可以方便地实现动态数组的功能,并且可以随意插入不同类型的对象,进行查找、插入和删除操作。这篇文章对于需要频繁进行查找、插入和删除操作的情况下,使用vector类是一个很好的选择。 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • 纠正网上的错误:自定义一个类叫java.lang.System/String的方法
    本文纠正了网上关于自定义一个类叫java.lang.System/String的错误答案,并详细解释了为什么这种方法是错误的。作者指出,虽然双亲委托机制确实可以阻止自定义的System类被加载,但通过自定义一个特殊的类加载器,可以绕过双亲委托机制,达到自定义System类的目的。作者呼吁读者对网上的内容持怀疑态度,并带着问题来阅读文章。 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • JavaSE笔试题-接口、抽象类、多态等问题解答
    本文解答了JavaSE笔试题中关于接口、抽象类、多态等问题。包括Math类的取整数方法、接口是否可继承、抽象类是否可实现接口、抽象类是否可继承具体类、抽象类中是否可以有静态main方法等问题。同时介绍了面向对象的特征,以及Java中实现多态的机制。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文整理了Java面试中常见的问题及相关概念的解析,包括HashMap中为什么重写equals还要重写hashcode、map的分类和常见情况、final关键字的用法、Synchronized和lock的区别、volatile的介绍、Syncronized锁的作用、构造函数和构造函数重载的概念、方法覆盖和方法重载的区别、反射获取和设置对象私有字段的值的方法、通过反射创建对象的方式以及内部类的详解。 ... [详细]
author-avatar
hazouri林_978
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有