Foxit PDF SDK
fs_ocr.h
浏览该文件的文档.
1 #if (defined(_WIN32) || defined(_WIN64)) || (defined(__linux__) && defined(__x86_64__) && !defined(__ANDROID__))
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 
94 class OCREngine FS_FINAL : public Object {
95  public:
114  static ErrorCode Initialize(const wchar_t* ocr_resource_path);
115 
143  static ErrorCode Initialize(const wchar_t* ocr_resource_path, bool is_shared_cpu_cores_mode);
144 
152  static void Release();
153 
165  static void SetLogFile(const char* log_file_path);
166 
178  static void SetLogFile(const wchar_t* log_file_path);
179 
200  static void SetLanguages(const wchar_t* languages);
201 
211  static void SetOCRCallback(OCRCallback* callback);
212 };
213 
215 class OCRConfig FS_FINAL : public Object {
216  public:
221  :is_detect_pictures(true)
222  ,is_remove_noise(true)
223  ,is_correct_skew(true)
228  ,confidence(0){}
229 
244  this->is_detect_pictures = is_detect_pictures;
245  this->is_remove_noise = is_remove_noise;
246  this->is_correct_skew = is_correct_skew;
247  this->is_enable_text_extraction_mode = is_enable_text_extraction_mode;
248  this->is_sequentially_process = is_sequentially_process;
249  this->is_auto_overwrite_resolution = is_auto_overwrite_resolution;
250  this->resolution_to_overwrite = resolution_to_overwrite;
251  this->confidence = confidence;
252  }
253 
270  this->is_detect_pictures = is_detect_pictures;
271  this->is_remove_noise = is_remove_noise;
272  this->is_correct_skew = is_correct_skew;
273  this->is_enable_text_extraction_mode = is_enable_text_extraction_mode;
274  this->is_sequentially_process = is_sequentially_process;
275  this->is_auto_overwrite_resolution = is_auto_overwrite_resolution;
276  this->resolution_to_overwrite = resolution_to_overwrite;
277  this->confidence = confidence;
278  }
279 
287  OCRConfig& operator=(const OCRConfig& other) {
295  confidence = other.confidence;
296  return (*this);
297  }
298 
306  bool operator!=(const OCRConfig& other) {
311  return true;
312  return false;
313  }
314 
322 
331 
340 
353 
364 
372 
380 
389 };
390 
392 class OCRSettingData FS_FINAL : public Object {
393  public:
398 
408  this->pdf_doc = pdf_doc;
409  this->page_range = page_range;
410  this->is_editable = is_editable;
411  this->ocr_config = ocr_config;
412  }
413 
425  this->pdf_doc = pdf_doc;
426  this->page_range = page_range;
427  this->is_editable = is_editable;
428  this->ocr_config = ocr_config;
429  }
430 
439  pdf_doc = data.pdf_doc;
440  page_range = data.page_range;
441  is_editable = data.is_editable;
442  ocr_config = data.ocr_config;
443  return (*this);
444  }
445 
453  bool operator!=(const OCRSettingData& data) {
454  if (pdf_doc != data.pdf_doc || page_range != data.page_range || is_editable != data.is_editable || ocr_config != data.ocr_config)
455  return true;
456  return false;
457  }
458 
461 
464 
470 
473 };
474 
477 
478 
482 class OCRSuspectInfo FS_FINAL : public Object {
483  public:
486 
489 
492 };
493 
496 
497 
503 class OCR FS_FINAL : public Base {
504  public:
510  typedef enum _OCRConvertFormat {
512  e_OCRConvertFormatDOCX = 0,
514  e_OCRConvertFormatDOC = 1,
516  e_OCRConvertFormatRTF = 2,
518  e_OCRConvertFormatXLSX = 3,
520  e_OCRConvertFormatXLS = 4,
522  e_OCRConvertFormatPPTX = 5,
524  e_OCRConvertFormatHTML = 6
525  } OCRConvertFormat;
526 
530  OCR();
531 
537  OCR(const OCR& other);
538 
539  // 强烈建议用户不要使用此方法;否则可能出现未知情况。
540  explicit OCR(FS_HANDLE handle);
542  ~OCR();
543 
551  OCR& operator = (const OCR& other);
559  bool operator == (const OCR& other) const;
567  bool operator != (const OCR& other) const;
568 
576  bool IsEmpty() const;
577 
592  void OCRPDFPage(pdf::PDFPage pdf_page, bool is_editable, OCRProgressCallback* callback = NULL);
593 
609  void OCRPDFPage(pdf::PDFPage pdf_page, bool is_editable, const OCRConfig& config, OCRProgressCallback* callback = NULL);
610 
625  void OCRPDFDocument(pdf::PDFDoc pdf_doc, bool is_editable, OCRProgressCallback* callback = NULL);
626 
642  void OCRPDFDocument(pdf::PDFDoc pdf_doc, bool is_editable, const OCRConfig& config, OCRProgressCallback* callback = NULL);
643 
663  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);
664 
685  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);
686 
687 #if (defined(_WIN32) || defined(_WIN64)) || (defined(__linux__) && defined(__x86_64__) && !defined(__ANDROID__))
688 
704  void OCRPDFDocuments(const ocr::OCRSettingDataArray& settingdata_array, OCRProgressCallback* callback = NULL);
705 #endif
706 
716  OCRSuspectInfoArray GetOCRSuspectsInfo(pdf::PDFDoc ocred_pdf_doc);
717 };
718 
719 } // namespace ocr
720 } // namespace addon
721 } // namespace foxit
722 
723 #endif // FS_OCR_H_
724 
725 #endif // #if (defined(_WIN32) || defined(_WIN64)) || (defined(__linux__) && defined(__x86_64__) && !defined(__ANDROID__))
Definition: fs_ocr.h:215
bool is_detect_pictures
决定是否检测图片。true 表示在分析过程中将检测图片。 false 表示不检测图片,PDF文档图像上的图片内容可能被解释为文本。 如果您只想从图像中提取文本,可以将此选项设置为 false。 默认值:...
Definition: fs_ocr.h:321
Definition: fs_common.h:1368
CFX_Object Object
对象类型。
Definition: fs_basictypes.h:220
bool is_editable
决定OCR结果是否可编辑。true 表示OCR结果是可编辑的。 false 表示OCR结果只能搜索但不能编辑。
Definition: fs_ocr.h:469
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:407
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:242
virtual bool NeedToCancelNow(const wchar_t *info)=0
用于取消当前OCR进度的回调函数。
宽字符串类
Definition: fx_string.h:1457
Definition: fs_pdfdoc.h:768
OCRConfig()
构造函数。
Definition: fs_ocr.h:220
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:424
static ErrorCode Initialize(const wchar_t *ocr_resource_path)
初始化OCR引擎。
OCRSettingData()
构造函数。
Definition: fs_ocr.h:397
WString suspect_words
OCR识别后的可疑词汇。
Definition: fs_ocr.h:491
int resolution_to_overwrite
用于覆盖 PDF 文档图像分辨率的分辨率值(DPI)。
Definition: fs_ocr.h:379
bool operator==(const char *str1, const CFX_ByteString &str2)
检查两个字节字符串是否相等。
Definition: fs_basictypes.h:128
OCRSettingData & operator=(const OCRSettingData &data)
赋值操作符。
Definition: fs_ocr.h:438
Definition: fs_ocr.h:94
virtual bool IsImageIgnored(foxit::pdf::graphics::ImageObject *image_object)=0
用于确定是否应从OCR文本识别中排除图像对象的回调函数。
Definition: fs_ocr.h:503
bool is_sequentially_process
决定OCR引擎是否在一个进程上顺序处理页面。
Definition: fs_ocr.h:363
ErrorCode
错误代码的枚举。
Definition: fs_basictypes.h:236
bool is_auto_overwrite_resolution
决定是否自动设置分辨率。
Definition: fs_ocr.h:371
OCRConfig & operator=(const OCRConfig &other)
赋值操作符。
Definition: fs_ocr.h:287
foxit::RectF words_rect
在 PDF坐标系统 中可疑词汇的边界矩形
Definition: fs_ocr.h:488
pdf::PDFDoc pdf_doc
需要进行OCR的有效PDF文档。
Definition: fs_ocr.h:460
Definition: fs_pdfpage.h:417
void * FS_HANDLE
句柄类型。
Definition: fs_basictypes.h:213
int page_index
页面索引。
Definition: fs_ocr.h:485
通用定义和类的头文件。
bool operator!=(const OCRSettingData &data)
不等于操作符。
Definition: fs_ocr.h:453
Definition: fs_ocr.h:482
Definition: fs_basictypes.h:471
bool operator!=(const OCRConfig &other)
不等于操作符。
Definition: fs_ocr.h:306
PDF页面相关定义和类的头文件。
static void SetLanguages(const wchar_t *languages)
设置要包含在语言数据库中进行OCR识别的语言名称。
bool is_correct_skew
决定是否启用偏斜校正。true 表示启用偏斜校正。 false 表示不启用偏斜校正。 默认值:true。
Definition: fs_ocr.h:339
Foxit命名空间。
Definition: fs_pdf3d.h:26
int confidence
用于判断识别文本是否可靠的置信度阈值。
Definition: fs_ocr.h:388
Definition: fs_ocr.h:43
bool is_remove_noise
决定是否去除PDF图像的噪声。如果PDF图像包含一些噪声,比如随机的黑点或斑点,这可能很有用。 如果图像上字母的线条很细,应将此选项设置为 false,否则会影响文本的识别。 true 表示图像中的噪声...
Definition: fs_ocr.h:330
#define NULL
空指针值。
Definition: fx_system.h:792
bool is_enable_text_extraction_mode
决定是否启用文本提取模式。
Definition: fs_ocr.h:352
static void SetOCRCallback(OCRCallback *callback)
设置用于取消OCR进度的回调对象。
Definition: fs_ocr.h:392
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:268
common::Range page_range
需要进行OCR的页面范围。
Definition: fs_ocr.h:463
Definition: fs_pdfgraphicsobject.h:1102
OCRConfig ocr_config
OCRConfig 对象。
Definition: fs_ocr.h:472
static void Release()
释放OCR引擎。
Definition: fx_coordinates.h:771