{"id":23060906,"url":"https://github.com/syncfusionexamples/maui-ocr-scanner-app","last_synced_at":"2025-10-09T14:48:05.605Z","repository":{"id":98096023,"uuid":"563760709","full_name":"SyncfusionExamples/maui-ocr-scanner-app","owner":"SyncfusionExamples","description":"This repository contains the MAUI sample to OCR the images and convert it to the PDF","archived":false,"fork":false,"pushed_at":"2024-12-02T14:29:57.000Z","size":544,"stargazers_count":5,"open_issues_count":2,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-01T22:58:05.912Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SyncfusionExamples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-11-09T09:25:17.000Z","updated_at":"2024-12-02T14:31:21.000Z","dependencies_parsed_at":"2025-06-01T14:54:54.939Z","dependency_job_id":"75b743fa-da13-4999-82bc-247e0e4a97b9","html_url":"https://github.com/SyncfusionExamples/maui-ocr-scanner-app","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SyncfusionExamples/maui-ocr-scanner-app","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2Fmaui-ocr-scanner-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2Fmaui-ocr-scanner-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2Fmaui-ocr-scanner-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2Fmaui-ocr-scanner-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SyncfusionExamples","download_url":"https://codeload.github.com/SyncfusionExamples/maui-ocr-scanner-app/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyncfusionExamples%2Fmaui-ocr-scanner-app/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262739080,"owners_count":23356648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-16T03:15:40.164Z","updated_at":"2025-10-09T14:48:00.560Z","avatar_url":"https://github.com/SyncfusionExamples.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OCR in .NET MAUI: Building an Image Processing Application\n\nThe [Syncfusion\u0026reg; .NET MAUI library](https://www.syncfusion.com/document-processing/pdf-framework/maui/pdf-library) is used to create, read, and edit PDF documents. This repository contains the example of .NET MAUI OCR scanner application to scan images using OCR scanner and convert them to PDF document with searchable text using the [Syncfusion\u0026reg; OCR library](https://www.syncfusion.com/document-processing/pdf-framework/net/pdf-library/ocr-process).   \n\n## Steps to build an OCR scanner application in .NET MAUI\n### Step 1: Download the project\nDownload this project to a location in your disk. Then open the solution file using Visual Studio. \n\n### Step 2: Rebuild solution\nRebuild the solution to install the required NuGet package. \n\n### Step 3: Add UI elements\nIn this application, we get images from the user in the following ways:\n* Open the camera and capture images such as receipts, notes, documents, photos, and business cards.\n* Select images from the device's photo gallery.\n\n**Open camera and capture image**\n\nAdd a button in the UI to open the camera.\n\n```csharp\n\n\u003cButton x:Name=\"CameraBtn\"\n\t  Text=\"Open Camera\"\n          Clicked=\"OnCameraClicked\"\n          HorizontalOptions=\"Center\" /\u003e\n\n```\n\nUse the MAUI [MediaPicker](https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/device-media/picker) API to open and capture images using the camera. The MediaPicker API needs permission to access the camera and internal storage. Refer to the [get started](https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/device-media/picker?view=net-maui-7.0\u0026tabs=android#get-started) section of the API documentation to set the permissions.\n\nCall the CapturePhotoAsync method to open the camera and capture the image. Refer to the following code example which is implemented in in [MainPage.xaml.cs](OCRScanner/MainPage.xaml.cs) file. \n\n```csharp\n\nprivate void OnCameraClicked(object sender, EventArgs e)\n{\n   TakePhoto();\n}\n//Open camera and take photo\npublic async void TakePhoto()\n{\n   if (MediaPicker.Default.IsCaptureSupported)\n   {\n      FileResult photo = await MediaPicker.Default.CapturePhotoAsync();\n      if (photo != null)\n      {\n          // Save the file into local storage.\n          string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);\n                \n          //Reduce the size of the image. \n          using Stream sourceStream = await photo.OpenReadAsync();\n          using SKBitmap sourceBitmap=SKBitmap.Decode(sourceStream);\n          int height = Math.Min(794, sourceBitmap.Height);\n                int width = Math.Min(794, sourceBitmap.Width);\n                \n          using SKBitmap scaledBitmap = sourceBitmap.Resize(new SKImageInfo(width, height),SKFilterQuality.Medium);\n          using SKImage scaledImage = SKImage.FromBitmap(scaledBitmap);\n                \n          using (SKData data = scaledImage.Encode())\n          {\n              File.WriteAllBytes(localFilePath, data.ToArray());\n          }\n               \n           //Create model and add to the collection\n           ImageModel model = new ImageModel() { ImagePath = localFilePath, Title = \"sample\", Description = \"Cool\" };\n           viewModel.Items.Add(model);\n      }\n   }\n}\n\n```\n\n**Select an image from the gallery** \n\nAdd a button in the UI to select an image.\n\n```csharp \n\n\u003cButton\n\tx:Name=\"CounterBtn\"\n\tText=\"Select Image\"\n\tClicked=\"OnCounterClicked\"\n\tHorizontalOptions=\"Center\" /\u003e\n\n``` \n\nUse the MAUI MediaPicker API to select images from the device's photo gallery. Use the PickPhotoAsync method to select images from the gallery. Refer to the following code example which is implemented in in [MainPage.xaml.cs](OCRScanner/MainPage.xaml.cs) file. \n\n```csharp\n\nprivate void OnCounterClicked(object sender, EventArgs e)\n{\n    PickPhoto();\n}\n\n//Select images from gallery.\npublic async void PickPhoto()\n{\n   if (MediaPicker.Default.IsCaptureSupported)\n   {\n       FileResult photo = await MediaPicker.Default.PickPhotoAsync();\n       \n       if (photo != null)\n       {\n          // Save the file into local storage.\n          string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);\n                \n          using Stream sourceStream = await photo.OpenReadAsync();\n          using FileStream localFileStream = File.OpenWrite(localFilePath);\n                \n          await sourceStream.CopyToAsync(localFileStream);\n                \n          ImageModel model = new ImageModel() { ImagePath = localFilePath, Title = \"sample\", Description = \"Cool\" };\n          viewModel.Items.Add(model);\n      }\n    }\n}\n\n```\n\nFinally, convert the image to PDF with OCR, so our simple UI looks like the following picture.\n![sample UI](OCRScanner/Images/convert-the-image-to-PDF-with-OCR.jpg)\n\nRefer to the [MainPage.xaml](OCRScanner/MainPage.xaml) file on GitHub for the complete UI.\n\n### Step 4: Convert images to PDF with OCR text\n\nHere, we use the Syncfusion\u0026reg; OCR library with the external Azure OCR engine to convert images to PDF. Refer to the following code example which is implemented in [MainPage.xaml.cs](OCRScanner/MainPage.xaml.cs) file. \n\nN\u003e Please refer to this [article](https://learn.microsoft.com/en-us/azure/cognitive-services/computer-vision/quickstarts-sdk/client-library) to configure and use the Azure Computer Vision OCR services. We have already created a class named [AzureOcrEngine.cs](OCRScanner/AzureOcrEngine.cs) to process images. You can use this class as it is in your project without any changes. You just need to add your subscription key and endpoint in the code.\n\n```csharp\n\npublic void ConvertToPDF()\n{\n    Task.Run(async () =\u003e\n    { \n    \n       PdfDocument finalDcoument = new PdfDocument();\n       if (viewModel.Items.Count == 0)\n          return;\n       using (OCRProcessor processor = new OCRProcessor())\n       {\n \n          processor.ExternalEngine = new AzureOcrEngine();\n          foreach (var item in viewModel.Items)\n          {\n             FileStream imageStream = new FileStream(item.ImagePath,FileMode.Open);\n             PdfDocument document = processor.PerformOCR(imageStream);\n             MemoryStream saveStream = new MemoryStream();\n             document.Save(saveStream);\n             document.Close(true);\n             PdfDocument.Merge(finalDcoument,saveStream);\n         }\n \n      }\n \n    MemoryStream fileSave = new MemoryStream();\n    finalDcoument.Save(fileSave);\n    fileSave.Position = 0;\n    finalDcoument.Close(true);\n            \n    Dispatcher.Dispatch(() =\u003e\n    {\n        popup.Close();\n        SaveService service = new SaveService();\n        service.SaveAndView(\"Output.pdf\", \"application/pdf\", fileSave);\n    });\n \n  });\n}\n\n```\n\nAfter executing the above code, you will get the following output.\n![sample output](OCRScanner/Images/Output.jpg)\n\nTo save the PDF document to external storage, add the platform-specific service classes. Refer to the respective classes in the following links:\n* [Android](OCRScanner/Platforms/Android/SaveAndroid.cs)\n* [Windows](OCRScanner/Platforms/Windows/SaveWindow.cs)\n* [iOS](OCRScanner/Platforms/iOS/SaveIOS.cs)\n* [Mac Catalyst](OCRScanner/Platforms/MacCatalyst/SaveMac.cs)\n\n# Resources\n*   **Product page:** [Syncfusion\u0026reg; PDF Framework](https://www.syncfusion.com/document-processing/pdf-framework/net)\n*   **Documentation page:** [Syncfusion\u0026reg; .NET PDF library](https://help.syncfusion.com/file-formats/pdf/overview)\n*   **Online demo:** [Syncfusion\u0026reg; .NET PDF library - Online demos](https://ej2.syncfusion.com/aspnetcore/PDF/CompressExistingPDF#/bootstrap5)\n*   **Blog:** [Syncfusion\u0026reg; .NET PDF library - Blog](https://www.syncfusion.com/blogs/category/pdf)\n*   **Knowledge Base:** [Syncfusion\u0026reg; .NET PDF library - Knowledge Base](https://www.syncfusion.com/kb/windowsforms/pdf)\n*   **EBooks:** [Syncfusion\u0026reg; .NET PDF library - EBooks](https://www.syncfusion.com/succinctly-free-ebooks)\n*   **FAQ:** [Syncfusion\u0026reg; .NET PDF library - FAQ](https://www.syncfusion.com/faq/)\n\n# Support and feedback\n*   For any other queries, reach our [Syncfusion\u0026reg; support team](https://www.syncfusion.com/support/directtrac/incidents/newincident?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples) or post the queries through the [community forums](https://www.syncfusion.com/forums?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples).\n*   Request new feature through [Syncfusion\u0026reg; feedback portal](https://www.syncfusion.com/feedback?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples).\n\n# License\nThis is a commercial product and requires a paid license for possession or use. Syncfusion’s licensed software, including this component, is subject to the terms and conditions of [Syncfusion's EULA](https://www.syncfusion.com/eula/es/?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples). You can purchase a licnense [here](https://www.syncfusion.com/sales/products?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples) or start a free 30-day trial [here](https://www.syncfusion.com/account/manage-trials/start-trials?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples).\n\n# About Syncfusion\u0026reg;\nFounded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion\u0026reg; has more than 26,000+ customers and more than 1 million users, including large financial institutions, Fortune 500 companies, and global IT consultancies.\n\nToday, we provide 1600+ components and frameworks for web ([Blazor](https://www.syncfusion.com/blazor-components?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), [ASP.NET Core](https://www.syncfusion.com/aspnet-core-ui-controls?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), [ASP.NET MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), [ASP.NET WebForms](https://www.syncfusion.com/jquery/aspnet-webforms-ui-controls?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), [JavaScript](https://www.syncfusion.com/javascript-ui-controls?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), [Angular](https://www.syncfusion.com/angular-ui-components?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), [React](https://www.syncfusion.com/react-ui-components?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), [Vue](https://www.syncfusion.com/vue-ui-components?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), and [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples)), mobile ([Xamarin](https://www.syncfusion.com/xamarin-ui-controls?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), [UWP](https://www.syncfusion.com/uwp-ui-controls?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), and [JavaScript](https://www.syncfusion.com/javascript-ui-controls?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples)), and desktop development ([WinForms](https://www.syncfusion.com/winforms-ui-controls?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), [WPF](https://www.syncfusion.com/wpf-ui-controls?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), [WinUI(Preview)](https://www.syncfusion.com/winui-controls?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples), [Flutter](https://www.syncfusion.com/flutter-widgets?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples) and [UWP](https://www.syncfusion.com/uwp-ui-controls?utm_source=github\u0026utm_medium=listing\u0026utm_campaign=github-docio-examples)). We provide ready-to-deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyncfusionexamples%2Fmaui-ocr-scanner-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyncfusionexamples%2Fmaui-ocr-scanner-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyncfusionexamples%2Fmaui-ocr-scanner-app/lists"}