Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

848818 -Added the OCR sample #55

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading