Scan server is a Free to use alternative to many expensive solutions out there that allow scanning documents from Web applications.
There are two projects:
- ScanServer: Compiles into a .exe that can be run a standalone app or as a service
- ScanServerInstaller: Create an MSI to make easier to download and install as Windows Service (Runs by default on http://localhost:5000).
Just run/install the app. List the devices on: http://localhost:5000/api/scanners
You can perform a scan and handle exceptions like this:
const scanResponse = await fetch(`http://localhost:5000/api/scan/${encodeURIComponent(scannerId)}`).catch(() => null);
if (!scanResponse) {
return Promise.reject('Failed to Perform Scan');
}
if (scanResponse.ok) {
return new File([await scanResponse.blob()], `Scan-${+new Date()}`, { type: scanResponse.headers.get('Content-Type')! });
} else {
console.error('Failed to perform scan', scanResponse);
if (scanResponse.status === 404) {
return Promise.reject('Scanner not found');
} else {
return Promise.reject('Failed to Perform Scan');
}
}
To build this project:
cd .\ScanServer
rm -r .\bin\
dotnet clean
dotnet publish ScanServer.csproj -c Release
cd ..\ScanServerInstaller
rm -r .\bin\
dotnet clean
dotnet build -c Release
To be able to attach the visual studio debugger on a running Windows Service, the project needs to be build in Debug and not release.
Make sure to disable single file...
dotnet build ScanServer.csproj -c Debug
Then create a Windows service using cmd as administrator and not powershell using the .exe in the debug file, make sure to stop the release server since they by default use the same port.
sc create ScanServerDebug binPath= "C:\Path\To\ScanServer\bin\Debug\net7.0\win-x64\ScanServer.exe" DisplayName= "Scan Server Debug" start= auto obj= "LocalSystem"
To uninstall start a command line as administrator and run:
sc stop ScanServer
sc delete ScanServer
Then delete the install folder.
A huge thank you to @cyanfish and it's NAPS2 SDK Project without whom/which building this would have taken a lot of time. If you want to donate, please donate to him using this link
Find a way to change the default port in the service either:
- by configuring the service in the installer
- Building the app with another default port while allowing --urls to work.