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
64 virtual bool IsImageIgnored(foxit::pdf::graphics::ImageObject* image_object) = 0;
65 };
66
71 class OCRProgressCallback {
72 public:
80 virtual void ProgressNotify(int current_rate) = 0;
81 };
82
94 class OCREngine FS_FINAL : public Object {
95 public:
115 static ErrorCode Initialize(const wchar_t* ocr_resource_path);
116
145 static ErrorCode Initialize(const wchar_t* ocr_resource_path, bool is_shared_cpu_cores_mode);
146
155 static void Release();
156
168 static void SetLogFile(const char* log_file_path);
169
181 static void SetLogFile(const wchar_t* log_file_path);
182
202 static void SetLanguages(const wchar_t* languages);
203
213 static void SetOCRCallback(OCRCallback* callback);
214 };
215
217 class OCRConfig FS_FINAL : public Object {
218 public:
222 OCRConfig()
223 :is_detect_pictures(true)
224 ,is_remove_noise(true)
225 ,is_correct_skew(true)
226 ,is_enable_text_extraction_mode(false)
227 ,is_sequentially_process(false)
228 ,is_auto_overwrite_resolution(true)
229 ,resolution_to_overwrite(300)
230 ,confidence(0){}
231
243 OCRConfig(bool is_detect_pictures, bool is_remove_noise, bool is_correct_skew, bool is_enable_text_extraction_mode, bool is_sequentially_process,
244 bool is_auto_overwrite_resolution, int resolution_to_overwrite, int confidence) {
245 this->is_detect_pictures = is_detect_pictures;
246 this->is_remove_noise = is_remove_noise;
247 this->is_correct_skew = is_correct_skew;
248 this->is_enable_text_extraction_mode = is_enable_text_extraction_mode;
249 this->is_sequentially_process = is_sequentially_process;
250 this->is_auto_overwrite_resolution = is_auto_overwrite_resolution;
251 this->resolution_to_overwrite = resolution_to_overwrite;
252 this->confidence = confidence;
253 }
254
269 void Set(bool is_detect_pictures, bool is_remove_noise, bool is_correct_skew, bool is_enable_text_extraction_mode, bool is_sequentially_process,
270 bool is_auto_overwrite_resolution, int resolution_to_overwrite, int confidence) {
271 this->is_detect_pictures = is_detect_pictures;
272 this->is_remove_noise = is_remove_noise;
273 this->is_correct_skew = is_correct_skew;
274 this->is_enable_text_extraction_mode = is_enable_text_extraction_mode;
275 this->is_sequentially_process = is_sequentially_process;
276 this->is_auto_overwrite_resolution = is_auto_overwrite_resolution;
277 this->resolution_to_overwrite = resolution_to_overwrite;
278 this->confidence = confidence;
279 }
280
288 OCRConfig& operator=(const OCRConfig& other) {
289 is_detect_pictures = other.is_detect_pictures;
290 is_remove_noise = other.is_remove_noise;
291 is_correct_skew = other.is_correct_skew;
292 is_enable_text_extraction_mode = other.is_enable_text_extraction_mode;
293 is_sequentially_process = other.is_sequentially_process;
294 is_auto_overwrite_resolution = other.is_auto_overwrite_resolution;
295 resolution_to_overwrite = other.resolution_to_overwrite;
296 confidence = other.confidence;
297 return (*this);
298 }
299
307 bool operator!=(const OCRConfig& other) {
308 if (is_detect_pictures != other.is_detect_pictures || is_remove_noise != other.is_remove_noise ||
309 is_correct_skew != other.is_correct_skew || is_enable_text_extraction_mode != other.is_enable_text_extraction_mode ||
310 is_sequentially_process != other.is_sequentially_process || is_auto_overwrite_resolution != other.is_auto_overwrite_resolution ||
311 resolution_to_overwrite != other.resolution_to_overwrite || confidence != other.confidence)
312 return true;
313 return false;
314 }
315
322 bool is_detect_pictures;
323
332 bool is_remove_noise;
333
341 bool is_correct_skew;
342
354 bool is_enable_text_extraction_mode;
355
366 bool is_sequentially_process;
367
374 bool is_auto_overwrite_resolution;
375
382 int resolution_to_overwrite;
383
392 int confidence;
393 };
394
396 class OCRSettingData FS_FINAL : public Object {
397 public:
401 OCRSettingData(){}
402
411 OCRSettingData(pdf::PDFDoc pdf_doc, const common::Range& page_range, bool is_editable, const OCRConfig& ocr_config) {
412 this->pdf_doc = pdf_doc;
413 this->page_range = page_range;
414 this->is_editable = is_editable;
415 this->ocr_config = ocr_config;
416 }
417
428 void Set(pdf::PDFDoc pdf_doc, const common::Range& page_range, bool is_editable, const OCRConfig& ocr_config) {
429 this->pdf_doc = pdf_doc;
430 this->page_range = page_range;
431 this->is_editable = is_editable;
432 this->ocr_config = ocr_config;
433 }
434
442 OCRSettingData& operator=(const OCRSettingData& data) {
443 pdf_doc = data.pdf_doc;
444 page_range = data.page_range;
445 is_editable = data.is_editable;
446 ocr_config = data.ocr_config;
447 return (*this);
448 }
449
457 bool operator!=(const OCRSettingData& data) {
458 if (pdf_doc != data.pdf_doc || page_range != data.page_range || is_editable != data.is_editable || ocr_config != data.ocr_config)
459 return true;
460 return false;
461 }
462
464 pdf::PDFDoc pdf_doc;
465
467 common::Range page_range;
468
473 bool is_editable;
474
476 OCRConfig ocr_config;
477 };
478
480 FSDK_DEFINE_ARRAY(OCRSettingDataArray, OCRSettingData)
481
482
487 class OCRSuspectInfo FS_FINAL : public Object {
488 public:
490 int page_index;
491
493 foxit::RectF words_rect;
494
496 WString suspect_words;
497 };
498
500 FSDK_DEFINE_ARRAY(OCRSuspectInfoArray, OCRSuspectInfo)
501
502
508 class OCR FS_FINAL : public Base {
509 public:
515 typedef enum _OCRConvertFormat {
517 e_OCRConvertFormatDOCX = 0,
519 e_OCRConvertFormatDOC = 1,
521 e_OCRConvertFormatRTF = 2,
523 e_OCRConvertFormatXLSX = 3,
525 e_OCRConvertFormatXLS = 4,
527 e_OCRConvertFormatPPTX = 5,
529 e_OCRConvertFormatHTML = 6
530 } OCRConvertFormat;
531
535 OCR();
536
542 OCR(const OCR& other);
543
544 // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
545 explicit OCR(FS_HANDLE handle);
547 ~OCR();
548
556 OCR& operator = (const OCR& other);
564 bool operator == (const OCR& other) const;
572 bool operator != (const OCR& other) const;
573
581 bool IsEmpty() const;
582
597 void OCRPDFPage(pdf::PDFPage pdf_page, bool is_editable, OCRProgressCallback* callback = NULL);
598
614 void OCRPDFPage(pdf::PDFPage pdf_page, bool is_editable, const OCRConfig& config, OCRProgressCallback* callback = NULL);
615
630 void OCRPDFDocument(pdf::PDFDoc pdf_doc, bool is_editable, OCRProgressCallback* callback = NULL);
631
647 void OCRPDFDocument(pdf::PDFDoc pdf_doc, bool is_editable, const OCRConfig& config, OCRProgressCallback* callback = NULL);
648
668 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);
669
690 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);
691
692 #if (defined(_WIN32) || defined(_WIN64)) || (defined(__linux__) && defined(__x86_64__) && !defined(__ANDROID__))
693
711 void OCRPDFDocuments(const ocr::OCRSettingDataArray& settingdata_array, OCRProgressCallback* callback = NULL);
712 #endif
713
723 OCRSuspectInfoArray GetOCRSuspectsInfo(pdf::PDFDoc ocred_pdf_doc);
724 };
725
726 } // namespace ocr
727 } // namespace addon
728 } // namespace foxit
729
730 #endif // FS_OCR_H_
731
732 #endif // #if (defined(_WIN32) || defined(_WIN64)) || (defined(__linux__) && defined(__x86_64__) && !defined(__ANDROID__))
foxit::addon::ocr::OCRConfig
Definition: fs_ocr.h:217
foxit::addon::ocr::OCRConfig::is_detect_pictures
bool is_detect_pictures
Decide whether to detect pictures. true means the pictures will be detected during analysis process....
Definition: fs_ocr.h:322
foxit::common::Range
Definition: fs_common.h:1368
foxit::Object
CFX_Object Object
Object type.
Definition: fs_basictypes.h:220
foxit::addon::ocr::OCRSettingData::is_editable
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:473
fs_pdfdoc.h
Header file for PDF document related definitions and classes.
foxit::addon::ocr::OCREngine::SetLogFile
static void SetLogFile(const char *log_file_path)
Set log file for OCR engine.
foxit::addon::ocr::OCRSettingData::OCRSettingData
OCRSettingData(pdf::PDFDoc pdf_doc, const common::Range &page_range, bool is_editable, const OCRConfig &ocr_config)
Constructor, with parameters.
Definition: fs_ocr.h:411
foxit::addon::ocr::OCRConfig::OCRConfig
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)
Constructor, with parameters.
Definition: fs_ocr.h:243
foxit::addon::ocr::OCRCallback::NeedToCancelNow
virtual bool NeedToCancelNow(const wchar_t *info)=0
A callback function used to cancel current OCR progress.
CFX_WideString
WIDE STRING CLASS.
Definition: fx_string.h:1461
foxit::pdf::PDFDoc
Definition: fs_pdfdoc.h:776
foxit::addon::ocr::OCRConfig::OCRConfig
OCRConfig()
Constructor.
Definition: fs_ocr.h:222
foxit::addon::ocr::OCRProgressCallback::ProgressNotify
virtual void ProgressNotify(int current_rate)=0
A callback function used to update current progress state data to user in order that user can update ...
foxit::addon::ocr::OCRSettingData::Set
void Set(pdf::PDFDoc pdf_doc, const common::Range &page_range, bool is_editable, const OCRConfig &ocr_config)
Set value.
Definition: fs_ocr.h:428
foxit::addon::ocr::OCREngine::Initialize
static ErrorCode Initialize(const wchar_t *ocr_resource_path)
Initialize OCR engine.
foxit::addon::ocr::OCRSettingData::OCRSettingData
OCRSettingData()
Constructor.
Definition: fs_ocr.h:401
foxit::addon::ocr::OCRProgressCallback
Definition: fs_ocr.h:71
foxit::addon::ocr::OCRSuspectInfo::suspect_words
WString suspect_words
Suspicious words after OCR recognition.
Definition: fs_ocr.h:496
foxit::addon::ocr::OCRConfig::resolution_to_overwrite
int resolution_to_overwrite
The resolution (DPI) used to overwrite the image resolution of PDF document.
Definition: fs_ocr.h:382
operator==
bool operator==(const char *str1, const CFX_ByteString &str2)
Check if two byte strings are equal.
Definition: fs_basictypes.h:128
foxit::addon::ocr::OCRSettingData::operator=
OCRSettingData & operator=(const OCRSettingData &data)
Assign operator.
Definition: fs_ocr.h:442
foxit::addon::ocr::OCREngine
Definition: fs_ocr.h:94
foxit::addon::ocr::OCRCallback::IsImageIgnored
virtual bool IsImageIgnored(foxit::pdf::graphics::ImageObject *image_object)=0
A callback function used to determine whether an image object should be excluded from OCR text recogn...
foxit::addon::ocr::OCR
Definition: fs_ocr.h:508
foxit::addon::ocr::OCRSuspectInfoArray
Definition: fs_ocr.h:500
foxit::addon::ocr::OCRConfig::is_sequentially_process
bool is_sequentially_process
Decide whether the OCR engine will process pages sequentially on one process.
Definition: fs_ocr.h:366
foxit::ErrorCode
ErrorCode
Enumeration for error code.
Definition: fs_basictypes.h:236
foxit::addon::ocr::OCRConfig::is_auto_overwrite_resolution
bool is_auto_overwrite_resolution
Decide whether to set the resolution automatically.
Definition: fs_ocr.h:374
foxit::addon::ocr::OCRConfig::operator=
OCRConfig & operator=(const OCRConfig &other)
Assign operator.
Definition: fs_ocr.h:288
foxit::addon::ocr::OCRSuspectInfo::words_rect
foxit::RectF words_rect
The box rectangle, in PDF coordinate system for suspicious words.
Definition: fs_ocr.h:493
foxit::addon::ocr::OCRSettingDataArray
Definition: fs_ocr.h:480
foxit::addon::ocr::OCRSettingData::pdf_doc
pdf::PDFDoc pdf_doc
A valid PDF document that need to be OCR.
Definition: fs_ocr.h:464
foxit::pdf::PDFPage
Definition: fs_pdfpage.h:412
foxit::FS_HANDLE
void * FS_HANDLE
Handle type.
Definition: fs_basictypes.h:213
foxit::addon::ocr::OCRSuspectInfo::page_index
int page_index
The index of page.
Definition: fs_ocr.h:490
fs_common.h
Header file for common definitions and classes.
foxit::addon::ocr::OCRSettingData::operator!=
bool operator!=(const OCRSettingData &data)
Not equal operator.
Definition: fs_ocr.h:457
foxit::addon::ocr::OCRSuspectInfo
Definition: fs_ocr.h:487
foxit::Base
Definition: fs_basictypes.h:451
foxit::addon::ocr::OCRConfig::operator!=
bool operator!=(const OCRConfig &other)
Not equal operator.
Definition: fs_ocr.h:307
fs_pdfpage.h
Header file for PDF page related definitions and classes.
foxit::addon::ocr::OCREngine::SetLanguages
static void SetLanguages(const wchar_t *languages)
Set the name of languages which would be included in the language database for doing OCR.
foxit::addon::ocr::OCRConfig::is_correct_skew
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:341
foxit
Foxit namespace.
Definition: fs_pdf3d.h:26
foxit::addon::ocr::OCRConfig::confidence
int confidence
The confidence threshold used to determine whether the recognized text is reliable.
Definition: fs_ocr.h:392
foxit::addon::ocr::OCRCallback
Definition: fs_ocr.h:43
foxit::addon::ocr::OCRConfig::is_remove_noise
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:332
NULL
#define NULL
The null-pointer value.
Definition: fx_system.h:792
foxit::addon::ocr::OCRConfig::is_enable_text_extraction_mode
bool is_enable_text_extraction_mode
Decide whether to enable text extraction mode.
Definition: fs_ocr.h:354
foxit::addon::ocr::OCREngine::SetOCRCallback
static void SetOCRCallback(OCRCallback *callback)
Set the callback object used to cancel OCR progress.
foxit::addon::ocr::OCRSettingData
Definition: fs_ocr.h:396
foxit::addon::ocr::OCRConfig::Set
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)
Set value.
Definition: fs_ocr.h:269
foxit::addon::ocr::OCRSettingData::page_range
common::Range page_range
The range of pages that need to be OCR.
Definition: fs_ocr.h:467
foxit::pdf::graphics::ImageObject
Definition: fs_pdfgraphicsobject.h:1118
foxit::addon::ocr::OCRSettingData::ocr_config
OCRConfig ocr_config
The OCRConfig object.
Definition: fs_ocr.h:476
foxit::addon::ocr::OCREngine::Release
static void Release()
Release OCR engine.
CFX_FloatRect
Definition: fx_coordinates.h:771