Skip to content

Commit

Permalink
Added the OCR sample
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyalakshmit committed Sep 27, 2023
1 parent 4a14f00 commit 3ad7d30
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32819.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Get-image-rotation-angle-from-OCR", "Get-image-rotation-angle-from-OCR\Get-image-rotation-angle-from-OCR.csproj", "{166945E9-DA34-4693-B891-BC5BA23BD990}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{166945E9-DA34-4693-B891-BC5BA23BD990}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{166945E9-DA34-4693-B891-BC5BA23BD990}.Debug|Any CPU.Build.0 = Debug|Any CPU
{166945E9-DA34-4693-B891-BC5BA23BD990}.Release|Any CPU.ActiveCfg = Release|Any CPU
{166945E9-DA34-4693-B891-BC5BA23BD990}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {512C0288-3F23-4E95-A770-4A809BC41D5E}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Get_image_rotation_angle_from_OCR</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.PDF.OCR.NET" Version="23.1.38" />
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// See https://aka.ms/new-console-template for more information

using Syncfusion.OCRProcessor;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
using System.Reflection.Metadata;

//Initialize the OCR processor.
using (OCRProcessor processor = new OCRProcessor())
{
//Get the stream from an image file.
FileStream stream = new FileStream(@"../../../Input.pdf", FileMode.Open);
//Set the OCR language to process.
PdfLoadedDocument document = new PdfLoadedDocument(stream);
//Set the OCR language.
processor.Settings.Language = Languages.English;
//Set the Unicode font to preserve the Unicode characters in a PDF document.
processor.TesseractPath = @"../../../TesseractBinaries/";
processor.Settings.PageSegment = PageSegMode.AutoOsd;
processor.PerformOCR(document, 0, 0, @"../../../Tessdata", out OCRLayoutResult result);
float angle = 0;
if (result != null)
{
foreach (var page in result.Pages)
{
angle = page.ImageRotation;
if (angle == 180)
{ document.Pages[0].Rotation = PdfPageRotateAngle.RotateAngle90; }
if (angle == 90)
{ document.Pages[0].Rotation = PdfPageRotateAngle.RotateAngle270; }
}
}

//Create file stream.
using (FileStream outputFileStream = new FileStream("../../../Output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
document.Save(outputFileStream);
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 3ad7d30

Please sign in to comment.