Knowledgebase (2311)
Children categories
Spire.OCR for .NET is a professional OCR library that supports recognizing text from Images (such as JPG, PNG, GIF, BMP, and TIFF) in both .NET Framework and .NET Core applications. In this article, we will explain how to use Spire.OCR for .NET to read text from images in .NET Framework applications.
Step 1: Create a console application (.NET Framework) in Visual Studio.


Step 2: Change the platform target of the application to X64.
In the application's solution explorer, right-click on the solution name and then click "Properties".

Change the platform target of the application to X64. This step must be performed since Spire.OCR only supports 64-bit platforms.

Step 3: Add a reference to Spire.OCR for .NET DLL in the application.
We recommend installing Spire.OCR for .NET through NuGet (Note: only Spire.OCR for .NET Version 1.8.0 or above supports working with .NET Framework). The detailed steps are as follows:
- In the application's solution explorer, right-click on the solution name or "References" and select "Manage NuGet Packages".
- Click the "Browse" tab and search for Spire.OCR.
- Click "Install" to install Spire.OCR.

Step 4: Copy DLLs from the "packages" directory to the "Debug" directory in the application.
When you install Spire.OCR through NuGet, NuGet downloads the packages and puts them in your application under a directory called "packages". You need to find the "Spire.OCR" directory under the "packages" directory, then copy the DLLs under the "Spire.OCR" directory (packages\Spire.OCR.1.8.0\runtimes\win-x64\native) to the "Debug" directory of your application.

Now you have successfully included Spire.OCR in your .NET Framework application. You can refer to the following code example to read text from images using Spire.OCR.
- C#
using Spire.OCR;
using System.IO;
namespace OcrImage
{
internal class Program
{
static void Main(string[] args)
{
//Create an instance of the OcrScanner class
OcrScanner scanner = new OcrScanner();
//Call the OcrScanner.Scan() method to scan text from an image
scanner.Scan("image.png");
//Save the scanned text to a .txt file
string text = scanner.Text.ToString();
File.WriteAllText("output.txt", text);
}
}
}
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
When you are handling a PDF document with lots of pages, you will most likely need to add new pages to include more information or remove some redundant pages. In this article, you will learn how to programmatically add or delete pages in a PDF document using Spire.PDF for C++.
- Add a Blank Page at the End of a PDF Document in C++
- Insert a Blank Page After a Specific Page in PDF in C++
- Delete an Existing Page in a PDF Document in C++
Install Spire.PDF for C++
There are two ways to integrate Spire.PDF for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.PDF for C++ in a C++ Application
Add a Blank Page at the End of a PDF Document in C++
Spire.PDF for C++ allows you to add an empty page with specific size and margins at the end of the document using PdfDocument->GetPages()->Add(SizeF* size, PdfMargins* margins) method. The following are the detailed steps.
- Create a PdfDocument object.
- Load a sample PDF document using PdfDocument->LoadFromFile() method.
- Create an empty page with the specified size and margins and then append it to the end of the document using PdfDocument->GetPages()->Add(SizeF* size, PdfMargins* margins) method.
- Save the result document using PdfDocument->SaveToFile () method.
- C++
#include "Spire.Pdf.o.h"
using namespace Spire::Pdf;
using namespace std;
int main() {
//Specify input and output file paths
wstring inputFile = L"Data\\input.pdf";
wstring outputFile = L"Output\\InsertEmptyPageAtEnd.pdf";
//Create a PdfDocument object
PdfDocument* pdf = new PdfDocument();
//Load a PDF document
pdf->LoadFromFile(inputFile.c_str());
//Add an empty page at the end of the document
PdfMargins tempVar(0, 0);
pdf->GetPages()->Add(new SizeF(PdfPageSize::A4()), &tempVar);
//Save the result document
pdf->SaveToFile(outputFile.c_str());
pdf->Close();
delete pdf;
}

Insert a Blank Page After a Specific Page in PDF in C++
If you want to insert an empty page into a specific position of a PDF document, you can use the PdfDocument->GetPages()->Insert(int index) method. The following are the detailed steps.
- Create a PdfDocument object.
- Load a sample PDF document using PdfDocument->LoadFromFile() method.
- Create a blank page and insert it after a specified PDF page using PdfDocument->GetPages()->Insert(int index) method.
- Save the result document using PdfDocument->SaveToFile () method.
- C++
#include "Spire.Pdf.o.h"
using namespace Spire::Pdf;
using namespace std;
int main() {
//Specify input and output file paths
wstring inputFile = L"Data\\input.pdf";
wstring outputFile = L"Output\\InsertEmptyPage.pdf";
//Create a PdfDocument object
PdfDocument* pdf = new PdfDocument();
//Load a PDF document
pdf->LoadFromFile(inputFile.c_str());
//Insert a blank page as the second page
pdf->GetPages()->Insert(1);
//Save the result document
pdf->SaveToFile(outputFile.c_str());
pdf->Close();
delete pdf;
}

Delete an Existing Page in a PDF Document in C++
For PDF pages containing useless information, you can also remove them using Spire.PDF for C++. The following are the steps to delete a specific page in PDF.
- Create a PdfDocument object.
- Load a sample PDF document using PdfDocument->LoadFromFile() method.
- Remove a specified page from the document using PdfDocument->GetPages()->RemoveAt(int index) method.
- Save the result document using PdfDocument->SaveToFile () method.
- C++
#include "Spire.Pdf.o.h"
using namespace Spire::Pdf;
using namespace std;
int main() {
//Specify input and output file paths
wstring inputFile = L"Data\\input.pdf";
wstring outputFile = L"Output\\DeletePage.pdf";
//Create a PdfDocument object
PdfDocument* pdf = new PdfDocument();
//Load a PDF document
pdf->LoadFromFile(inputFile.c_str());
//Delete the first page in the document
pdf->GetPages()->RemoveAt(0);
//Save the result document
pdf->SaveToFile(outputFile.c_str());
pdf->Close();
delete pdf;
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Merging Excel files is an essential task when you need to summarize data stored in multiple Excel files. For instance, if you have sales reports for each quarter of the year, you might need to merge them into one file to get a more comprehensive view of the data for the entire year. By merging Excel files, you are able to concentrate on a single organized workbook instead of switching between multiple files. This streamlines your work process and improves efficiency. In this article, you will learn how to merge Excel files into one in C++ using Spire.XLS for C++ library.
Install Spire.XLS for C++
There are two ways to integrate Spire.XLS for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.XLS for C++ in a C++ Application
Merge Multiple Excel Workbooks into One in C++
You can merge multiple Excel workbooks into one by creating a new workbook, then copying worksheets in the original workbooks to the new workbook. The detailed steps are as follows:
- Put the paths of the original workbooks into a vector.
- Initialize a Workbook object to create a new workbook and clear the default worksheets in it.
- Initialize a temporary Workbook object.
- Iterate through the workbooks in the vector.
- Load the workbook into the temporary Workbook object using Workbook->LoadFromFile() method.
- Iterate through the worksheets in the workbook, then copy each worksheet from the workbook to the new workbook using Workbook->GetWorksheets()->AddCopy() method.
- Save the result workbook to file using Workbook->SaveToFile() method.
- C++
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
using namespace std;
int main()
{
//Put the paths of the workbooks into a vector
std::vector<std::wstring> files = { L"File1.xlsx", L"File2.xlsx", L"File3.xlsx" };;
//Initialize a Workbook object to create a new workbook
Workbook* newWorkbook = new Workbook();
newWorkbook->SetVersion(ExcelVersion::Version2013);
//Clear the default worksheets
newWorkbook->GetWorksheets()->Clear();
//Initialize a temporary Workbook object
Workbook* tempWorkbook = new Workbook();
//Iterate through the workbooks in the vector
for (auto file : files)
{
//Load the current workbook
tempWorkbook->LoadFromFile(file.c_str());
//Iterate through all worksheets in the workbook
for (int i = 0; i < tempWorkbook->GetWorksheets()->GetCount(); i++)
{
Worksheet* sheet = tempWorkbook->GetWorksheets()->Get(i);
//Copy each worksheet from the workbook to the new workbook
(dynamic_cast<XlsWorksheetsCollection*>(newWorkbook->GetWorksheets()))->AddCopy(sheet, WorksheetCopyType::CopyAll);
}
}
//Save the result workbook to file
newWorkbook->SaveToFile(L"MergeExcelFiles.xlsx", ExcelVersion::Version2013);
newWorkbook->Dispose();
tempWorkbook->Dispose();
delete newWorkbook;
delete tempWorkbook;
}

Merge Multiple Excel Worksheets into One in C++
You can merge multiple worksheets into one worksheet by copying the used data range in the original worksheets to the destination worksheet. The following steps show you how to merge two worksheets within the same workbook into one worksheet:
- Initialize a Workbook object and load an Excel workbook using Workbook->LoadFromFile() method.
- Get the two worksheets that need to be merged using Workbook->GetWorksheets()->Get(int index) method (the sheet index here is zero-based).
- Get the used range of the second worksheet using Worksheet->GetAllocatedRange() method.
- Specify the destination range in the first worksheet using Worksheet->GetRange(int row, int column) method (the row and column indexes here are 1-based).
- Copy the used range of the second worksheet to the destination range in the first worksheet using CellRange->Copy(CellRange destRange) method.
- Remove the second worksheet from the workbook using XlsWorksheet->Remove() method.
- Save the result workbook to file using Workbook->SaveToFile() method.
- C++
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
using namespace std;
int main()
{
//Initialize a Workbook object
Workbook* workbook = new Workbook();
//Load an Excel workbook
workbook->LoadFromFile(L"Sample.xlsx");
//Get the first worksheet
Worksheet* sheet1 = workbook->GetWorksheets()->Get(0);
//Get the second worksheet
Worksheet* sheet2 = workbook->GetWorksheets()->Get(1);
//Get the used range in the second worksheet
CellRange* sourceRange = sheet2->GetAllocatedRange();
//Specify the destination range in the first worksheet
CellRange* destRange = sheet1->GetRange(sheet1->GetLastRow() + 1, 1);
//Copy the used range of the second worksheet to the destination range in the first worksheet
sourceRange->Copy(destRange);
//Remove the second worksheet
sheet2->Remove();
//Save the result workbook to file
workbook->SaveToFile(L"MergeExcelWorksheets.xlsx", ExcelVersion::Version2013);
workbook->Dispose();
delete workbook;
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.