热门标签 | 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;
}

 


推荐阅读
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社区 版权所有