Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/782401e51497cec4542317a0b9e4e57f to your computer and use it in GitHub Desktop.
Save aspose-com-gists/782401e51497cec4542317a0b9e4e57f to your computer and use it in GitHub Desktop.
Convert Image to Searchable PDF with OCR using C++
Convert Image to Searchable PDF with OCR using C++
// Source file path
std::string image_path = "SourceDirectory\\sample.png";
// Prepare buffer for result (in symbols, len_byte = len * sizeof(wchar_t))
const size_t len = 4096;
wchar_t buffer[len] = { 0 };
// Set the recognition settings
RecognitionSettings settings;
settings.language_alphabet = language::eng;
settings.save_format = file_format::pdf;
// Perform the OCR operation and save the output file.
asposeocr_page_save(image_path.c_str(), "OutputDirectory\\ImageToPDF.pdf", settings);
// Source file path
std::string image_path = "SourceDirectory\\skewSample.png";
// Prepare buffer for result (in symbols, len_byte = len * sizeof(wchar_t))
const size_t len = 4096;
wchar_t buffer[len] = { 0 };
// Calculate skew angle
std::double_t angle = asposeocr_get_skew(image_path.c_str());
// Set the recognition settings
RecognitionSettings settings;
settings.language_alphabet = language::eng;
settings.save_format = file_format::pdf;
settings.skew = angle;
// Perform the OCR operation and save the output file.
asposeocr_page_save(image_path.c_str(), "OutputDirectory\\SkewedImageToPDF.pdf", settings);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment