Images and scanned documents may contain textual information that you might need to process further. You might have captured pictures of text documents using your smartphone that you want to convert to editable documents. For this, performing OCR on the images can prove to be helpful. With OCR, you can convert images to searchable and editable Word documents. To that end, this article will teach you how to convert images to Word documents using C++.
- C++ API for Converting Images to Word Documents
- Convert Image to Word Document using C++
- Convert Skewed Image to Word Document using C++
C++ API for Converting Images to Word Documents
Aspose.OCR for C++ is an optical character recognition API that can extract text from images. The API also enables you to convert images to Word Documents like DOC, DOCX, and TXT files. You can either install the API through NuGet or download it directly from the Downloads section.
PM> Install-Package Aspose.OCR.Cpp
Convert Image to Word Document using C++
Often you might need to search or edit the text in images, but you are unable to do so. By performing OCR on such images and converting them to Word documents, you can search and edit the text as needed. To achieve this, please follow the steps given below.
- Prepare the buffer for the result.
- Set the value of RecognitionSettings.save_format struct member as file_format::docx.
- Perform the OCR operation on the image and save the Word file using the asposeocr_page_save(const char * image_path, const char * save_path, RecognitionSettings settings) method.
The following sample code shows how to convert an image to a Word document using C++:
Convert Skewed Image to Word Document using C++
Images and scanned documents can sometimes be skewed. With Aspose.OCR for C++ API, you can perform OCR on skewed images. The following are the steps to convert a skewed image to a Word document:
- Prepare the buffer for the result.
- Calculate the skew angle of the image using the asposeocr_get_skew(const char * image_path) method.
- Set the value of RecognitionSettings.save_format struct member as file_format::docx.
- Specify the skew angle using RecognitionSettings.skew struct member.
- Perform the OCR operation on the image and save the Word file using the asposeocr_page_save(const char * image_path, const char * save_path, RecognitionSettings settings) method.
The following sample code shows how to convert a skewed image to a Word document using C++:
Get a Free License
In order to try the API without evaluation limitations, you can request a free temporary license.
Conclusion
In this article, you have learned how to convert images to Word documents using C++. Furthermore, you have seen how to calculate and use the skew angle of an image to perform OCR on skewed images. The API provides many additional features that you can explore in detail by visiting the official documentation. In case of any questions, please feel free to reach us on our free support forum.