Foxit PDF SDK
fs_ocr.h
Go to the documentation of this file.
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 };
67 class OCREngine FS_FINAL : public Object {
68  public:
88  static ErrorCode Initialize(const wchar_t* ocr_resource_path);
89 
118  static ErrorCode Initialize(const wchar_t* ocr_resource_path, bool is_shared_cpu_cores_mode);
119 
128  static void Release();
129 
141  static void SetLogFile(const char* log_file_path);
142 
154  static void SetLogFile(const wchar_t* log_file_path);
155 
175  static void SetLanguages(const wchar_t* languages);
176 
186  static void SetOCRCallback(OCRCallback* callback);
187 };
188 
190 class OCRConfig FS_FINAL : public Object {
191  public:
196  :is_detect_pictures(true)
197  ,is_remove_noise(true)
198  ,is_correct_skew(true)
200  ,is_sequentially_process(false) {}
201 
211  this->is_detect_pictures = is_detect_pictures;
212  this->is_remove_noise = is_remove_noise;
213  this->is_correct_skew = is_correct_skew;
214  this->is_enable_text_extraction_mode = is_enable_text_extraction_mode;
215  this->is_sequentially_process = is_sequentially_process;
216  }
217 
230  this->is_detect_pictures = is_detect_pictures;
231  this->is_remove_noise = is_remove_noise;
232  this->is_correct_skew = is_correct_skew;
233  this->is_enable_text_extraction_mode = is_enable_text_extraction_mode;
234  this->is_sequentially_process = is_sequentially_process;
235  }
236 
244  OCRConfig& operator=(const OCRConfig& other) {
250  return (*this);
251  }
252 
260  bool operator!=(const OCRConfig& other) {
264  return true;
265  return false;
266  }
267 
275 
285 
294 
307 
319 };
320 
322 class OCRSettingData FS_FINAL : public Object {
323  public:
328 
338  this->pdf_doc = pdf_doc;
339  this->page_range = page_range;
340  this->is_editable = is_editable;
341  this->ocr_config = ocr_config;
342  }
343 
355  this->pdf_doc = pdf_doc;
356  this->page_range = page_range;
357  this->is_editable = is_editable;
358  this->ocr_config = ocr_config;
359  }
360 
369  pdf_doc = data.pdf_doc;
370  page_range = data.page_range;
371  is_editable = data.is_editable;
372  ocr_config = data.ocr_config;
373  return (*this);
374  }
375 
383  bool operator!=(const OCRSettingData& data) {
384  if (pdf_doc != data.pdf_doc || page_range != data.page_range || is_editable != data.is_editable || ocr_config != data.ocr_config)
385  return true;
386  return false;
387  }
388 
391 
394 
400 
403 };
404 
407 
408 
413 class OCRSuspectInfo FS_FINAL : public Object {
414  public:
417 
420 
423 };
424 
427 
428 
434 class OCR FS_FINAL : public Base {
435  public:
441  typedef enum _OCRConvertFormat {
443  e_OCRConvertFormatDOCX = 0,
445  e_OCRConvertFormatDOC = 1,
447  e_OCRConvertFormatRTF = 2,
449  e_OCRConvertFormatXLSX = 3,
451  e_OCRConvertFormatXLS = 4,
453  e_OCRConvertFormatPPTX = 5,
455  e_OCRConvertFormatHTML = 6
456  } OCRConvertFormat;
457 
461  OCR();
462 
468  OCR(const OCR& other);
469 
470  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
471  explicit OCR(FS_HANDLE handle);
473  ~OCR();
474 
482  OCR& operator = (const OCR& other);
490  bool operator == (const OCR& other) const;
498  bool operator != (const OCR& other) const;
499 
507  bool IsEmpty() const;
508 
521  void OCRPDFPage(pdf::PDFPage pdf_page, bool is_editable);
522 
536  void OCRPDFPage(pdf::PDFPage pdf_page, bool is_editable, const OCRConfig& config);
537 
550  void OCRPDFDocument(pdf::PDFDoc pdf_doc, bool is_editable);
551 
565  void OCRPDFDocument(pdf::PDFDoc pdf_doc, bool is_editable, const OCRConfig& config);
566 
584  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);
585 
604  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);
605 
606 #if (defined(_WIN32) || defined(_WIN64)) || (defined(__linux__) && defined(__x86_64__) && !defined(__ANDROID__))
607 
623  void OCRPDFDocuments(const ocr::OCRSettingDataArray& settingdata_array);
624 #endif
625 
635  OCRSuspectInfoArray GetOCRSuspectsInfo(pdf::PDFDoc ocred_pdf_doc);
636 };
637 
638 } // namespace ocr
639 } // namespace addon
640 } // namespace foxit
641 
642 #endif // FS_OCR_H_
643 
644 #endif // #if (defined(_WIN32) || defined(_WIN64)) || (defined(__linux__) && defined(__x86_64__) && !defined(__ANDROID__))
Definition: fs_ocr.h:190
bool is_detect_pictures
Decide whether to detect pictures. true means the pictures will be detected during analysis process....
Definition: fs_ocr.h:274
Definition: fs_common.h:1348
CFX_Object Object
Object type.
Definition: fs_basictypes.h:221
bool is_editable
Decide whether the OCR result is editable. true means the OCR result is editable. false means the OCR...
Definition: fs_ocr.h:399
Header file for PDF document related definitions and classes.
static void SetLogFile(const char *log_file_path)
Set log file for OCR engine.
OCRSettingData(pdf::PDFDoc pdf_doc, const common::Range &page_range, bool is_editable, const OCRConfig &ocr_config)
Constructor, with parameters.
Definition: fs_ocr.h:337
virtual bool NeedToCancelNow(const wchar_t *info)=0
A callback function used to cancel current OCR progress.
WIDE STRING CLASS.
Definition: fx_string.h:1461
Definition: fs_pdfdoc.h:772
OCRConfig()
Constructor.
Definition: fs_ocr.h:195
void Set(pdf::PDFDoc pdf_doc, const common::Range &page_range, bool is_editable, const OCRConfig &ocr_config)
Set value.
Definition: fs_ocr.h:354
static ErrorCode Initialize(const wchar_t *ocr_resource_path)
Initialize OCR engine.
OCRConfig(bool is_detect_pictures, bool is_remove_noise, bool is_correct_skew, bool is_enable_text_extraction_mode, bool is_sequentially_process)
Constructor, with parameters.
Definition: fs_ocr.h:210
void Set(bool is_detect_pictures, bool is_remove_noise, bool is_correct_skew, bool is_enable_text_extraction_mode, bool is_sequentially_process)
Set value.
Definition: fs_ocr.h:229
OCRSettingData()
Constructor.
Definition: fs_ocr.h:327
WString suspect_words
Suspicious words after OCR recognition.
Definition: fs_ocr.h:422
bool operator==(const char *str1, const CFX_ByteString &str2)
Check if two byte strings are equal.
Definition: fs_basictypes.h:128
OCRSettingData & operator=(const OCRSettingData &data)
Assign operator.
Definition: fs_ocr.h:368
Definition: fs_ocr.h:67
Definition: fs_ocr.h:434
bool is_sequentially_process
Decide whether the OCR engine will process pages sequentially on one process.
Definition: fs_ocr.h:318
ErrorCode
Enumeration for error code.
Definition: fs_basictypes.h:237
OCRConfig & operator=(const OCRConfig &other)
Assign operator.
Definition: fs_ocr.h:244
foxit::RectF words_rect
The box rectangle, in PDF coordinate system for suspicious words.
Definition: fs_ocr.h:419
pdf::PDFDoc pdf_doc
A valid PDF document that need to be OCR.
Definition: fs_ocr.h:390
Definition: fs_pdfpage.h:412
void * FS_HANDLE
Handle type.
Definition: fs_basictypes.h:214
int page_index
The index of page.
Definition: fs_ocr.h:416
Header file for common definitions and classes.
bool operator!=(const OCRSettingData &data)
Not equal operator.
Definition: fs_ocr.h:383
Definition: fs_ocr.h:413
Definition: fs_basictypes.h:449
bool operator!=(const OCRConfig &other)
Not equal operator.
Definition: fs_ocr.h:260
Header file for PDF page related definitions and classes.
static void SetLanguages(const wchar_t *languages)
Set the name of languages which would be included in the language database for doing OCR.
bool is_correct_skew
Decide whether to enable skew correction. true means to enable skew correction. false means not to en...
Definition: fs_ocr.h:293
Foxit namespace.
Definition: fs_pdf3d.h:27
Definition: fs_ocr.h:43
bool is_remove_noise
Decide whether to remove noise of the image of PDF. It can be useful if the image of the PDF contains...
Definition: fs_ocr.h:284
bool is_enable_text_extraction_mode
Decide whether to enable text extraction mode.
Definition: fs_ocr.h:306
static void SetOCRCallback(OCRCallback *callback)
Set the callback object used to cancel OCR progress.
Definition: fs_ocr.h:322
common::Range page_range
The range of pages that need to be OCR.
Definition: fs_ocr.h:393
OCRConfig ocr_config
The OCRConfig object.
Definition: fs_ocr.h:402
static void Release()
Release OCR engine.
Definition: fx_coordinates.h:771