Skip to content
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
27 changes: 27 additions & 0 deletions .devcontainer/aspose-ocr/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "Aspose OCR",
"image": "mcr.microsoft.com/dotnet/sdk:9.0",
"features": {},
"workspaceFolder": "/workspaces/Ivy-Examples/aspose-ocr",
"postCreateCommand": "dotnet tool install -g Ivy.Console",
"postStartCommand": "dotnet watch",
"forwardPorts": [5010],
"portsAttributes": {
"5010": {
"label": "Aspose OCR",
"onAutoForward": "openPreview"
}
},
"customizations": {
"vscode": {
"extensions": [
"ms-dotnettools.csharp",
"ms-vscode.powershell",
"ms-dotnettools.csdevkit"
]
},
"codespaces": {
"openFiles": ["Apps/ImageToTextApp.cs"]
}
}
}
62 changes: 40 additions & 22 deletions aspose-ocr/Apps/ImageToTextApp.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using Ivy.Aspose.OCR.Examples.Connections.OCR;
using Aspose.OCR;
using System.IO;

namespace Ivy.Aspose.OCR.Examples.Apps;
namespace AsposeOcrExample.Apps;

[App(icon: Icons.FileImage, path: ["Apps"])]
public class ImageToTextApp : ViewBase
{
public override object? Build()
{
var outputText = this.UseState<string>("");
var ocrService = UseService<IOCRService>();

var error = UseState<string?>(() => null);
var files = UseState<FileInput?>(() => null);
Expand All @@ -32,25 +31,44 @@ public class ImageToTextApp : ViewBase
"uploaded-image"
);

return Layout.Vertical(
Text.H1("Convert Image to text online").Color(Colors.Green),
Text.Block("Free OCR software to convert images or screenshots to text online"),
error.Value != null
? new Callout(error.Value, variant: CalloutVariant.Error)
: null,
files.ToFileInput(uploadUrl, "Upload Image").Accept("image/*"),
new Button("Recognize", _ =>
{
if (error.Value == null && fileBytes.Value != null)
var leftCard = new Card(
Layout.Vertical().Gap(6).Padding(3)
| Text.H2("Input")
| Text.Muted("Upload an image and run OCR")
| (error.Value != null ? new Callout(error.Value, variant: CalloutVariant.Error) : null)
| files.ToFileInput(uploadUrl, "Upload Image").Accept("image/*")
| new Button("Recognize").Primary().Icon(Icons.Eye)
.HandleClick(() =>
{
// Use the stored file bytes instead of file.Content
using var ms = new MemoryStream(fileBytes.Value);
outputText.Value = ocrService.ExtractText(ms);
fileBytes.Set((byte[]?)null); // Clear stored bytes once completed
}
}),
Text.Block("Output Text:"),
new ObservableView<string>(outputText)
).Align(Align.Center);
if (error.Value == null && fileBytes.Value != null)
{
using var ms = new MemoryStream(fileBytes.Value);

var recognitionEngine = new AsposeOcr();
using var source = new OcrInput(InputType.SingleImage);
source.Add(ms);

var results = recognitionEngine.Recognize(source);
outputText.Value = results.Count > 0 ? results[0].RecognitionText : string.Empty;
fileBytes.Set((byte[]?)null);
}
})
| Text.Small("This demo uses Aspose.OCR for .NET to recognize text.")
| Text.Markdown("Built with [Ivy Framework](https://github.com/Ivy-Interactive/Ivy-Framework) and [Aspose.OCR for .NET](https://products.aspose.com/ocr/net/)")
).Width(Size.Fraction(0.45f)).Height(130);

var rightCardBody = Layout.Vertical().Gap(4)
| Text.H2("Recognized Text")
| Text.Muted("Output")
| outputText.ToCodeInput()
.Width(Size.Full())
.Height(Size.Units(70))
.Language(Languages.Text);

var rightCard = new Card(rightCardBody).Width(Size.Fraction(0.45f)).Height(130);

return Layout.Horizontal().Gap(6).Align(Align.Center)
| leftCard
| rightCard;
}
}
Binary file removed aspose-ocr/Apps/aspose-OCR-image-to-text.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>CS8618;CS8603;CS8602;CS8604;CS9113</NoWarn>
<RootNamespace>Ivy.Aspose.OCR.Examples</RootNamespace>
<RootNamespace>AsposeOcrExample</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,7 +17,7 @@

<ItemGroup>
<PackageReference Include="Aspose.OCR" Version="25.9.0" />
<PackageReference Include="Ivy" Version="1.0.113.0" />
<PackageReference Include="Ivy" Version="1.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36429.23 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ivy.Aspose.OCR.Examples", "Ivy.Aspose.OCR.Examples.csproj", "{BA2A13B0-78C9-203B-1462-034AD42E4D37}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsposeOcrExample", "AsposeOcrExample.csproj", "{BA2A13B0-78C9-203B-1462-034AD42E4D37}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
33 changes: 0 additions & 33 deletions aspose-ocr/Connections/OCR/Aspose/AsposeOCRService.cs

This file was deleted.

6 changes: 0 additions & 6 deletions aspose-ocr/Connections/OCR/IOCRService.cs

This file was deleted.

31 changes: 0 additions & 31 deletions aspose-ocr/Connections/OCR/OCRConnection.cs

This file was deleted.

2 changes: 1 addition & 1 deletion aspose-ocr/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
global using System.Globalization;
global using System.Reactive.Linq;

namespace Ivy.Aspose.OCR.Examples;
namespace AsposeOcrExample;
15 changes: 11 additions & 4 deletions aspose-ocr/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@

using Ivy.Aspose.OCR.Examples.Apps;

using AsposeOcrExample.Apps;
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
var server = new Server();
#if DEBUG
server.UseHotReload();
#endif
server.AddAppsFromAssembly();
server.AddConnectionsFromAssembly();
var customHeader = Layout.Vertical().Gap(2)
| new Html(@"
<div>
<a href=""https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=Ivy-Interactive%2FIvy-Examples&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Faspose-ocr%2Fdevcontainer.json&location=EuropeWest"">
<img src=""https://github.com/codespaces/badge.svg"" alt=""Open in GitHub Codespaces"" />
</a>
</div>
");
var chromeSettings = new ChromeSettings()
.DefaultApp<ImageToTextApp>()
.UseTabs(preventDuplicates: true);
.UseTabs(preventDuplicates: true)
.Header(customHeader);
server.UseChrome(chromeSettings);
await server.RunAsync();
92 changes: 78 additions & 14 deletions aspose-ocr/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,88 @@
# Ivy.Aspose.OCR.Examples
# Aspose.OCR Image-to-Text

Web application created using [Ivy](https://github.com/Ivy-Interactive/Ivy-Framework).
<img width="1918" height="915" alt="Image" src="https://github.com/user-attachments/assets/8e08b435-7f77-48ee-b99b-94c1a1ab88f1" />

## Created Using Ivy

Web application created using [Ivy-Framework](https://github.com/Ivy-Interactive/Ivy-Framework).

**Ivy** - The ultimate framework for building internal tools with LLM code generation by unifying front-end and back-end into a single C# codebase. With Ivy, you can build robust internal tools and dashboards using C# and AI assistance based on your existing database.

Ivy is a web framework for building interactive web applications using C# and .NET.

## How it works
## Interactive Example For OCR (Image To Text)

This example showcases extracting text from images using Aspose.OCR with a simple two-panel UI: upload on the left, recognized text on the right.

**What This Application Does:**

- **Upload Image**: Select an image file and run OCR
- **Text Extraction**: Recognize text from the uploaded image
- **Monospaced Viewer**: See output in a clean, plain-text viewer
- **Validation**: Basic size check with friendly error messages

**Technical Implementation:**

- Uses Aspose.OCR `AsposeOcr` with `OcrInput(InputType.SingleImage)`
- Adds uploaded image stream via `source.Add(stream)` and calls `Recognize`
- Shows the first `RecognitionResult.RecognitionText` in a `CodeInput`
- Single C# view (`Apps/ImageToTextApp.cs`) built with Ivy UI primitives

## One-Click Development Environment

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=Ivy-Interactive%2FIvy-Examples&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Faspose-ocr%2Fdevcontainer.json&location=EuropeWest)

Click the badge above to open Ivy Examples repository in GitHub Codespaces with:
- **.NET 9.0** SDK pre-installed
- **Ready-to-run** development environment
- **No local setup** required

## How to Run

1. **Prerequisites**: .NET 9+ SDK
2. **Navigate to the example**:
```bash
cd aspose-ocr
```
3. **Restore dependencies**:
```bash
dotnet restore
```
4. **Run the application**:
```bash
dotnet watch
```
5. **Open your browser** to the URL shown in the terminal (typically `http://localhost:5010`)

## How to Deploy

Deploy this example to Ivy's hosting platform:

1. **Navigate to the example**:
```bash
cd aspose-ocr
```
2. **Deploy to Ivy hosting**:
```bash
ivy deploy
```
This will deploy your OCR application with a single command.

## Licensing & Trial Limitations

**Aspose.OCR for .NET** is a commercial library that can be used in trial (evaluation) mode without a license.

This web application demonstrates OCR (Optical Character Recognition) using Ivy and Aspose.OCR. Users can upload an image (JPEG, up to 1MB), and the app extracts text from the image using an OCR service. The workflow is:
### Trial Mode Restrictions

1. Upload an image using the provided form.
2. The app validates the file size and type.
3. On clicking "Recognize", the image is processed and text is extracted.
4. The recognized text is displayed on the page.
When running without a license, the following limitations apply:

## Run
- If the recognized image contains **more than 300 characters**, only the **first 300 characters** are recognized.
- If the recognized image contains **less than 300 characters**, only the **first 60%** are recognized.

```
dotnet watch
```
For more licensing options (metered, embedded resources, stream), see the [official licensing documentation](https://docs.aspose.com/ocr/net/licensing/).

## Output Screenshot
## Learn More

![OCR Example](Apps/aspose-OCR-image-to-text.png)
- Aspose.OCR for .NET overview: [products.aspose.com/ocr/net](https://products.aspose.com/ocr/net/)
- Aspose.OCR Licensing: [docs.aspose.com/ocr/net/licensing](https://docs.aspose.com/ocr/net/licensing/)
- Ivy Documentation: [docs.ivy.app](https://docs.ivy.app)
2 changes: 1 addition & 1 deletion crm-vc/Vc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Assets/**/*" />
<ProjectReference Include="D:\Repos\_Ivy\Ivy-Framework\Ivy\Ivy.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Ivy" Version="1.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Design" Version="1.1.6" />
Expand Down