Contact Support
Perform OCR in Mac
6 Dec 20242 minutes to read
The Syncfusion® .NET OCR library used to extract text from scanned PDFs and images in the Mac application.
Steps to perform OCR on entire PDF document in Mac
Step 1: Create a new .NET Core console application project.
Step 2: Select the project version.
Step 3: Install the Syncfusion.PDF.OCR.Net.Core NuGet package as a reference to your project from NuGet.org.
NOTE
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or from the NuGet feed, you also have to add “Syncfusion.Licensing” assembly reference and include a license key in your projects. Refer to this link to learn about registering the Syncfusion® license key in your application to use our components.
Step 4: Include the following Namespaces in the Program.cs file.
using Syncfusion.OCRProcessor;
using Syncfusion.Pdf.Parsing;
Step 5: Add the following code sample to the Program.cs file to Perform OCR in .NET Core application on Mac OS.
//Initialize the OCR processor.
using (OCRProcessor processor = new OCRProcessor())
{
FileStream fileStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read);
//Load a PDF document.
PdfLoadedDocument lDoc = new PdfLoadedDocument(fileStream);
//Set the OCR language to be processed.
processor.Settings.Language = Languages.English;
//Process OCR by providing the PDF document.
processor.PerformOCR(lDoc);
//Create memory stream.
MemoryStream stream = new MemoryStream();
//Save the document to the memory stream.
lDoc.Save(stream);
lDoc.Close();
//Set the position as '0'.
stream.Position = 0;
//Download the PDF document in the browser.
FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");
fileStreamResult.FileDownloadName = "OCR.pdf";
return fileStreamResult;
}
By executing the program, you will get a PDF document as follows.
A complete working sample can be downloaded from GitHub.
Click here to explore the rich set of Syncfusion® PDF library features.