ByteScout PDF Suite - C++ - PDF and OCR (Optical Character Recognition) with PDF Extractor SDK - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

ByteScout PDF Suite – C++ – PDF and OCR (Optical Character Recognition) with PDF Extractor SDK

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Suite – C++ – PDF and OCR (Optical Character Recognition) with PDF Extractor SDK

PDF and OCR (optical character recognition) with PDF extractor SDK in C++ with ByteScout PDF Suite

Simple tutorial on how to do PDF and OCR (optical character recognition) with PDF extractor SDK in C++

The documentation is crafted to assist you to apply the features on your side easily. ByteScout PDF Suite helps with PDF and OCR (optical character recognition) with PDF extractor SDK in C++. ByteScout PDF Suite is the set that includes 6 SDK products to work with PDF from generating rich PDF reports to extracting data from PDF documents and converting them to HTML. This bundle includes PDF (Generator) SDK, PDF Renderer SDK, PDF Extractor SDK, PDF to HTML SDK, PDF Viewer SDK and PDF Generator SDK for Javascript.

Save time on writing and testing code by using the code below and use it in your application. If you want to know how it works, then this C++ sample code should be copied and pasted into your application’s code editor. Then just compile and run it. Further improvement of the code will make it more robust.

If you want to try other samples for C++ then free trial version of ByteScout PDF Suite is available on our website.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

CPPExample.cpp
      
#include "stdafx.h" #include "comip.h" #import "c:\\Program Files\\Bytescout PDF Extractor SDK\\net4.00\\Bytescout.PDFExtractor.tlb" raw_interfaces_only using namespace Bytescout_PDFExtractor; int _tmain(int argc, _TCHAR* argv[]) { // Initialize COM. HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); // Create the interface pointer. _TextExtractorPtr pITextExtractor(__uuidof(TextExtractor)); // Set the registration name and key // Note: You should use _bstr_t or BSTR to pass string to the library because of COM requirements _bstr_t bstrRegName(L"DEMO"); pITextExtractor->put_RegistrationName(bstrRegName); _bstr_t bstrRegKey(L"DEMO"); pITextExtractor->put_RegistrationKey(bstrRegKey); // Load sample PDF document _bstr_t bstrPath(L"..\\..\\sample_ocr.pdf"); pITextExtractor->LoadDocumentFromFile(bstrPath); // Enable Optical Character Recognition (OCR) // in .Auto mode (SDK automatically checks if needs to use OCR or not) pITextExtractor->put_OCRMode(OCRMode_Auto); // Set the location of OCR language data files _bstr_t bstrOCRLangDataPath(L"c:\\Program Files\\Bytescout PDF Extractor SDK\\ocrdata"); pITextExtractor->put_OCRLanguageDataFolder(bstrOCRLangDataPath); // Set OCR language _bstr_t bstrOCRLanguage(L"eng"); pITextExtractor->put_OCRLanguage(bstrOCRLanguage); // Set PDF document rendering resolution pITextExtractor->put_OCRResolution(300); // You can also apply various preprocessing filters // to improve the recognition on low-quality scans. _ImagePreprocessingFiltersCollection* pIImagePreprocessingFilters; pITextExtractor->get_OCRImagePreprocessingFilters(&pIImagePreprocessingFilters); // Automatically deskew skewed scans //pIImagePreprocessingFilters->AddDeskew(); // Remove vertical or horizontal lines (sometimes helps to avoid OCR engine's page segmentation errors) //pIImagePreprocessingFilters->AddVerticalLinesRemover(); //pIImagePreprocessingFilters->AddHorizontalLinesRemover(); // Repair broken letters //pIImagePreprocessingFilters->AddDilate(); // Remove noise //pIImagePreprocessingFilters->AddMedian(); // Apply Gamma Correction //pIImagePreprocessingFilters->AddGammaCorrection(); // Add Contrast //pIImagePreprocessingFilters->AddContrast(20); // (!) You can use new OCRAnalyser class to find an optimal set of image preprocessing // filters for your specific document. // See "OCR Analyser" example. // Save extracted text to file _bstr_t bstrOutputFile(L"output.txt"); pITextExtractor->SaveTextToFile(bstrOutputFile); pITextExtractor->Release(); CoUninitialize(); return 0; }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

stdafx.cpp
      
// stdafx.cpp : source file that includes just the standard includes // CPPExample.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" // TODO: reference any additional headers you need in STDAFX.H // and not in this file

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

stdafx.h
      
// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // #pragma once #include "targetver.h" #include <stdio.h> #include <tchar.h> // TODO: reference additional headers your program requires here

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

targetver.h
      
#pragma once // Including SDKDDKVer.h defines the highest available Windows platform. // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. #include <SDKDDKVer.h>

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next