Foxit PDF SDK
fs_ocr.h
浏览该文件的文档.
1 #if (defined(_WIN32) || defined(_WIN64)) || defined(__linux__)
2 
16 #ifndef FS_OCR_H_
17 #define FS_OCR_H_
18 
19 #include "common/fs_common.h"
20 #include "pdf/fs_pdfdoc.h"
21 #include "pdf/fs_pdfpage.h"
22 
28 namespace foxit {
32 namespace addon {
36 namespace ocr {
43 class OCRCallback {
44  public:
54  virtual bool NeedToCancelNow(const wchar_t* info) = 0;
55 
64  virtual bool IsImageIgnored(foxit::pdf::graphics::ImageObject* image_object) = 0;
65 };
66 
72  public:
80  virtual void ProgressNotify(int current_rate) = 0;
81 };
82 
93 class OCREngine FS_FINAL : public Object {
94  public:
113  static ErrorCode Initialize(const wchar_t* ocr_resource_path);
114 
142  static ErrorCode Initialize(const wchar_t* ocr_resource_path, bool is_shared_cpu_cores_mode);
143 
151  static void Release();
152 
164  static void SetLogFile(const char* log_file_path);
165 
177  static void SetLogFile(const wchar_t* log_file_path);
178 
199  static void SetLanguages(const wchar_t* languages);
200 
210  static void SetOCRCallback(OCRCallback* callback);
211 };
212 
214 class OCRConfig FS_FINAL : public Object {
215  public:
220  :is_detect_pictures(true)
221  ,is_remove_noise(true)
222  ,is_correct_skew(true)
227  ,confidence(0){}
228 
243  this->is_detect_pictures = is_detect_pictures;
244  this->is_remove_noise = is_remove_noise;
245  this->is_correct_skew = is_correct_skew;
246  this->is_enable_text_extraction_mode = is_enable_text_extraction_mode;
247  this->is_sequentially_process = is_sequentially_process;
248  this->is_auto_overwrite_resolution = is_auto_overwrite_resolution;
249  this->resolution_to_overwrite = resolution_to_overwrite;
250  this->confidence = confidence;
251  }
252 
269  this->is_detect_pictures = is_detect_pictures;
270  this->is_remove_noise = is_remove_noise;
271  this->is_correct_skew = is_correct_skew;
272  this->is_enable_text_extraction_mode = is_enable_text_extraction_mode;
273  this->is_sequentially_process = is_sequentially_process;
274  this->is_auto_overwrite_resolution = is_auto_overwrite_resolution;
275  this->resolution_to_overwrite = resolution_to_overwrite;
276  this->confidence = confidence;
277  }
278 
286  OCRConfig& operator=(const OCRConfig& other) {
294  confidence = other.confidence;
295  return (*this);
296  }
297 
305  bool operator!=(const OCRConfig& other) {
310  return true;
311  return false;
312  }
313 
321 
330 
339 
352 
363 
371 
379 
388 };
389 
391 class OCRSettingData FS_FINAL : public Object {
392  public:
397 
407  this->pdf_doc = pdf_doc;
408  this->page_range = page_range;
409  this->is_editable = is_editable;
410  this->ocr_config = ocr_config;
411  }
412 
424  this->pdf_doc = pdf_doc;
425  this->page_range = page_range;
426  this->is_editable = is_editable;
427  this->ocr_config = ocr_config;
428  }
429 
438  pdf_doc = data.pdf_doc;
439  page_range = data.page_range;
440  is_editable = data.is_editable;
441  ocr_config = data.ocr_config;
442  return (*this);
443  }
444 
452  bool operator!=(const OCRSettingData& data) {
453  if (pdf_doc != data.pdf_doc || page_range != data.page_range || is_editable != data.is_editable || ocr_config != data.ocr_config)
454  return true;
455  return false;
456  }
457 
460 
463 
469 
472 };
473 
476 
477 
481 class OCRSuspectInfo FS_FINAL : public Object {
482  public:
485 
488 
491 };
492 
495 
496 
502 class OCR FS_FINAL : public Base {
503  public:
509  typedef enum _OCRConvertFormat {
511  e_OCRConvertFormatDOCX = 0,
513  e_OCRConvertFormatDOC = 1,
515  e_OCRConvertFormatRTF = 2,
517  e_OCRConvertFormatXLSX = 3,
519  e_OCRConvertFormatXLS = 4,
521  e_OCRConvertFormatPPTX = 5,
523  e_OCRConvertFormatHTML = 6
524  } OCRConvertFormat;
525 
529  OCR();
530 
536  OCR(const OCR& other);
537 
538  // 强烈建议用户不要使用此方法;否则可能出现未知情况。
539  explicit OCR(FS_HANDLE handle);
541  ~OCR();
542 
550  OCR& operator = (const OCR& other);
558  bool operator == (const OCR& other) const;
566  bool operator != (const OCR& other) const;
567 
575  bool IsEmpty() const;
576 
591  void OCRPDFPage(pdf::PDFPage pdf_page, bool is_editable, OCRProgressCallback* callback = NULL);
592 
608  void OCRPDFPage(pdf::PDFPage pdf_page, bool is_editable, const OCRConfig& config, OCRProgressCallback* callback = NULL);
609 
624  void OCRPDFDocument(pdf::PDFDoc pdf_doc, bool is_editable, OCRProgressCallback* callback = NULL);
625 
641  void OCRPDFDocument(pdf::PDFDoc pdf_doc, bool is_editable, const OCRConfig& config, OCRProgressCallback* callback = NULL);
642 
662  void OCRConvertTo(OCRConvertFormat format, const wchar_t* src_pdf_path, const wchar_t* password, const wchar_t* saved_file_path, common::Range page_range, bool is_retain_flowing_text, OCRProgressCallback* callback = NULL);
663 
684  void OCRConvertTo(OCRConvertFormat format, const wchar_t* src_pdf_path, const wchar_t* password, const wchar_t* saved_file_path, common::Range page_range, bool is_retain_flowing_text, const OCRConfig& config, OCRProgressCallback* callback = NULL);
685 
686 #if (defined(_WIN32) || defined(_WIN64)) || defined(__linux__)
687 
703  void OCRPDFDocuments(const ocr::OCRSettingDataArray& settingdata_array, OCRProgressCallback* callback = NULL);
704 #endif
705 
715  OCRSuspectInfoArray GetOCRSuspectsInfo(pdf::PDFDoc ocred_pdf_doc);
716 };
717 
718 } // namespace ocr
719 } // namespace addon
720 } // namespace foxit
721 
722 #endif // FS_OCR_H_
723 
724 #if (defined(_WIN32) || defined(_WIN64)) || defined(__linux__)
Definition: fs_ocr.h:214
bool is_detect_pictures
决定是否检测图片。true 表示在分析过程中将检测图片。 false 表示不检测图片,PDF文档图像上的图片内容可能被解释为文本。 如果您只想从图像中提取文本,可以将此选项设置为 false。 默认值:...
Definition: fs_ocr.h:320
Definition: fs_common.h:1364
CFX_Object Object
对象类型。
Definition: fs_basictypes.h:221
bool is_editable
决定OCR结果是否可编辑。true 表示OCR结果是可编辑的。 false 表示OCR结果只能搜索但不能编辑。
Definition: fs_ocr.h:468
PDF文档相关定义和类的头文件。
static void SetLogFile(const char *log_file_path)
为OCR引擎设置日志文件。
OCRSettingData(pdf::PDFDoc pdf_doc, const common::Range &page_range, bool is_editable, const OCRConfig &ocr_config)
带参数的构造函数。
Definition: fs_ocr.h:406
OCRConfig(bool is_detect_pictures, bool is_remove_noise, bool is_correct_skew, bool is_enable_text_extraction_mode, bool is_sequentially_process, bool is_auto_overwrite_resolution, int resolution_to_overwrite, int confidence)
带参数的构造函数。
Definition: fs_ocr.h:241
virtual bool NeedToCancelNow(const wchar_t *info)=0
用于取消当前OCR进度的回调函数。
宽字符串类
Definition: fx_string.h:1457
Definition: fs_pdfdoc.h:771
OCRConfig()
构造函数。
Definition: fs_ocr.h:219
virtual void ProgressNotify(int current_rate)=0
用于向用户更新当前进度状态数据的回调函数,以便用户更新进度条。
void Set(pdf::PDFDoc pdf_doc, const common::Range &page_range, bool is_editable, const OCRConfig &ocr_config)
设置值。
Definition: fs_ocr.h:423
static ErrorCode Initialize(const wchar_t *ocr_resource_path)
初始化OCR引擎。
OCRSettingData()
构造函数。
Definition: fs_ocr.h:396
WString suspect_words
OCR识别后的可疑词汇。
Definition: fs_ocr.h:490
int resolution_to_overwrite
用于覆盖 PDF 文档图像分辨率的分辨率值(DPI)。
Definition: fs_ocr.h:378
bool operator==(const char *str1, const CFX_ByteString &str2)
检查两个字节字符串是否相等。
Definition: fs_basictypes.h:128
OCRSettingData & operator=(const OCRSettingData &data)
赋值操作符。
Definition: fs_ocr.h:437
Definition: fs_ocr.h:93
virtual bool IsImageIgnored(foxit::pdf::graphics::ImageObject *image_object)=0
用于确定是否应从OCR文本识别中排除图像对象的回调函数。
Definition: fs_ocr.h:502
bool is_sequentially_process
决定OCR引擎是否在一个进程上顺序处理页面。
Definition: fs_ocr.h:362
ErrorCode
错误代码的枚举。
Definition: fs_basictypes.h:237
bool is_auto_overwrite_resolution
决定是否自动设置分辨率。
Definition: fs_ocr.h:370
OCRConfig & operator=(const OCRConfig &other)
赋值操作符。
Definition: fs_ocr.h:286
foxit::RectF words_rect
在 PDF坐标系统 中可疑词汇的边界矩形
Definition: fs_ocr.h:487
pdf::PDFDoc pdf_doc
需要进行OCR的有效PDF文档。
Definition: fs_ocr.h:459
Definition: fs_pdfpage.h:421
void * FS_HANDLE
句柄类型。
Definition: fs_basictypes.h:214
int page_index
页面索引。
Definition: fs_ocr.h:484
通用定义和类的头文件。
bool operator!=(const OCRSettingData &data)
不等于操作符。
Definition: fs_ocr.h:452
Definition: fs_ocr.h:481
Definition: fs_basictypes.h:449
bool operator!=(const OCRConfig &other)
不等于操作符。
Definition: fs_ocr.h:305
PDF页面相关定义和类的头文件。
static void SetLanguages(const wchar_t *languages)
设置要包含在语言数据库中进行OCR识别的语言名称。
bool is_correct_skew
决定是否启用偏斜校正。true 表示启用偏斜校正。 false 表示不启用偏斜校正。 默认值:true。
Definition: fs_ocr.h:338
Foxit命名空间。
Definition: fs_taggedpdf.h:27
int confidence
用于判断识别文本是否可靠的置信度阈值。
Definition: fs_ocr.h:387
Definition: fs_ocr.h:43
bool is_remove_noise
决定是否去除PDF图像的噪声。如果PDF图像包含一些噪声,比如随机的黑点或斑点,这可能很有用。 如果图像上字母的线条很细,应将此选项设置为 false,否则会影响文本的识别。 true 表示图像中的噪声...
Definition: fs_ocr.h:329
#define NULL
空指针值。
Definition: fx_system.h:792
bool is_enable_text_extraction_mode
决定是否启用文本提取模式。
Definition: fs_ocr.h:351
static void SetOCRCallback(OCRCallback *callback)
设置用于取消OCR进度的回调对象。
Definition: fs_ocr.h:391
void Set(bool is_detect_pictures, bool is_remove_noise, bool is_correct_skew, bool is_enable_text_extraction_mode, bool is_sequentially_process, bool is_auto_overwrite_resolution, int resolution_to_overwrite, int confidence)
设置值。
Definition: fs_ocr.h:267
common::Range page_range
需要进行OCR的页面范围。
Definition: fs_ocr.h:462
Definition: fs_pdfgraphicsobject.h:1102
OCRConfig ocr_config
OCRConfig 对象。
Definition: fs_ocr.h:471
static void Release()
释放OCR引擎。
Definition: fx_coordinates.h:771