The following must be installed before proceeding with next steps:
-
NET Core 3.1 SDK and NET 5 SDK https://dotnet.microsoft.com/download
- .NET runtime is installed automatically by SDK and should be installed separately only if target machine will be used exclusively for running application
- NET core 3.1 is used for most projects while .NET 5 is used for Blazor in this solution
-
MongoDB https://www.mongodb.com/
2.1 Optional docker image can be used for this step https://hub.docker.com/_/mongo
- to fetch the image from repo:
docker pull mongo - create and run a container based on image via
docker run --name mongo01 mongo
- to fetch the image from repo:
There are multiple ways to perform a build for the solution.
Since solution contains a web app (Blazor Web) and console app you can build them individually or as a single build
This method is not so recommended since it will output everything from build to save folder. (Both web app and console app)
-
Open a powershell / command-prompt / shell window
-
Go to directory where this document is located (
cd) -
Build solution using
dotnet build src\ -o build-all\- command above specifies the following:
dotnet=> .NET Command Line Interfacebuild=> perform build actionsrc\=> location of source code and.slnfile (.sln files referances all projects inside)-o build-all\=> output build to a folder name "build-all" in current directory
This will build only the Blazor web app.
-
Open a powershell / command-prompt / shell window
-
Go to directory where this document is located (
cd) -
Build solution using
dotnet build src\InvoiceManagement.App.Web -o build-web\- command above specifies the following:
dotnet=> .NET Command Line Interfacebuild=> perform build actionsrc\InvoiceManagement.App.Web=> location of source code and.csprojfile used to determine dependencies-o build-web\=> output build to a folder name "build-web" in current directory
This will build only the console app
-
Open a powershell / command-prompt / shell window
-
Go to directory where this document is located (
cd) -
Build solution using
dotnet build src\InvoiceManagement.App.ConsoleApp -o build-console\- command above specifies the following:
dotnet=> .NET Command Line Interfacebuild=> perform build actionsrc\InvoiceManagement.App.ConsoleApp=> location of source code and.csprojfile used to determine dependencies-o build-console\=> output build to a folder name "build" in current directory
Project can be configured using appsettings.json file which, by default, it is located in project's respective build folder. Depending on build type performed above it will be located in output folder chosen previously.
The provided appsettings has a structure with 2 relevant sections for the moment:
-
Logging - used to configure logging using default
Microsoft.Extensions.Loggingpackage -
more info here
-
DatabaseSetting - used to specify connection string to Mongo Server and Database used
- by default:
mongodb://localhost:27017/mydb?readPreference=primary&appname=MongoDB%20Compass&ssl=false
- by default:
In order to run the console application you should:
- navigate to build folder. For example
build-console - execute resulting executable
- InvoiceManagement.App.ConsoleApp.exe for Windows
- ./InvoiceManagement.App.ConsoleApp for unix based system
- dotnet InvoiceManagement.App.ConsoleApp.dll - run platform independent as long as dotnet CLI is installed
- follow prompts from console
In order to run the blazor web server you should:
- navigate to build folder
- execute resulting executable
- InvoiceManagement.App.Web.exe for Windows
- ./InvoiceManagement.App.Web for unix based system
- dotnet InvoiceManagement.App.Web.dll - run platform independent as long as dotnet CLI is installed
- look at console output. It should display where app is running.
Now listening on: http://localhost:5000\
- open a browser on said address and test it
Implementation details can be found in InvoiceManagement.Infrastructure\InvoiceScanners project.
There are 2 types of parsing that are implemented:
- Photo Scanning (OCR)
- PDF parsing
For each type of parsing there are one or more implementations added but only one active.
Photo Scanning is done using IronOcr library while PDF parsing is done using ByteScout. Regardless of library used, they all impose a limitation on their demo version.
For Photo Scanning, IronOcr has the advantage of using Teserract OCR which has good Open Source Support, good performance and a well documented .NET API. Its disadvantage would be it's hard to find/master and heavy documentation but it could also be it it's advantage. Licencing is done using a trial key which was provided for 30 days by Iron Software support for purpose of POC.
Using Bytescout for PDF parsing was the go-to choice since it was easy to set-up and fast learning curve compared to other pdf parsing libraries. A lot of documentation and examples can be found here. It has support for extraction of text within a region. Its biggest disadvantage in doing so would be hard to adapt, change and lacking fluent API. On its demo version, random words from scanned document get replaced by *DEMO* and could lead to parsing failures
Another alternative to PDF parsing could be GroupDocs which would be fantastic for writing your own pdf formats and parsing them back since it is based on a template defined in code. Unfortunately parsing other template formats requires a lot of time to set-up and define a template from existing one.
Lastly, IronOcr has its equivalent for PDF parsing called IronPdf. It has almost the same advantages as its equivalent but same goes for disadvantages. Extracting text is pretty each but results are combined in a way that is hard to parse into usable tabular structure without heavy regex usage.