Skip to content
maussoftPublic

About

Scan to PDF or PNG on Windows with a scanner or a webcam, written in Go

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

scan4win

Windows Fax and Scan is old and rarely updated. scan4win does the part of it that is still of use: scan, crop, and save as PDF or PNG. It works with the scanner on your desk, with a webcam, and with photos of paper from your phone. There is no fax. Written in Go with Windigo.

scan4win

Every page that you scan is added to the same document, until you click New. To split, merge or annotate PDF files there is pdf4win.

Nothing is sent anywhere. The only network access is the update check that you start yourself.

Features

  • Scanners with a Windows driver (WIA): the glass, the feeder, and both sides of the sheets in the feeder.
  • Webcams: put a sheet under it and hold it still, and scan4win takes the picture by itself.
  • JPEG and PNG pictures: with Import, by dropping them on the window, or on the command line. The way a phone was held is taken into account.
  • Finds the paper in a photo, cuts it out, makes it straight and takes the shadows off.
  • Color, grayscale, or black and white, at 100 to 600 dpi. The default is color at 150 dpi.
  • Guesses the size of the paper: A3, A4, A5, A6, Letter or Legal.
  • Turn and crop, move and delete pages, with undo and redo.
  • Saves a PDF with all pages, or a PNG file for every page.
  • Copies a page to the clipboard.
  • Asks to save when you click New or close the window.
  • Follows the light and dark app mode of Windows.
  • Checks for a newer release on request (Help, Check for Updates). Nothing is checked automatically.

Scanning

Choose the scanner next to the Scan button and click Scan. Settings has the color, the resolution, the size of the paper, and whether to scan from the glass or the feeder. With "Automatic Paper Size" a scanner scans A4, or Letter when that is the usual paper in the region that Windows is set to.

The settings are for what you scan from then on, and also change the page that is shown. Black and white is made by scan4win and not by the scanner, so a page can go back to grayscale. A page of a scanner keeps its resolution and its size: scan it again for another one.

A scanner needs a WIA driver, which comes with Windows or with the scanner. Scanners that only have a TWAIN driver are not supported: most of those drivers are 32-bit, and cannot be used by a 64-bit program.

Using a webcam

Choose the webcam and click Start Webcam. scan4win does not turn a webcam on before that. Put a sheet of paper under it, on something that is darker than the paper. A line shows where the paper is. When it lies still, scan4win collects pictures for about a second and combines them into one that is sharper and has less noise than each of them. Then put down the next sheet. Esc turns the webcam off.

Space takes a picture at once, also when no paper is found. Turn "Webcam Takes Pictures by Itself" off in Settings to only take pictures that way.

How much can be read depends on the webcam. One of 1920 x 1080 sees a whole A4 at about 90 dpi when the sheet is upright in the picture, and at about 130 dpi when it is on its side. That is enough for usual text. Combining pictures helps, but does not make a scanner of it. Turn the page with Ctrl+L or Ctrl+R.

Finding the paper

When the corners are not right, click Corners. It shows the whole picture with a handle at each corner of the paper. Drag them and press Enter. A picture without paper in it is kept whole.

The size of the paper is a guess. A4, Letter and Legal have different shapes. A3, A4, A5 and A6 have the same shape, so scan4win looks at how high the letters are: usual text is about as large on every size of paper. A sheet with very large or very small letters can be taken for another size, and one with hardly any text is taken for A4. The title of the window tells the size, and Settings can set it. The size matters for printing, and for how many pixels a page gets.

Saving

Ctrl+S saves the document. Pages that you add after that go to the same file when you save again. A PNG file holds one page, so a document with more pages gets files with a number: Scan-01.png, Scan-02.png and so on.

Color and grayscale pages are JPEG pictures in the PDF. Black and white pages are stored without loss, and are a lot smaller. There is no text recognition: a PDF holds pictures of the pages.

scan4win does not open PDF files, so pages cannot be added to a document once it is closed.

Keyboard

Key Action
Space Scan, start the webcam, or take a picture
Esc Cancel, or turn the webcam off
Enter Apply the corners
Ctrl+N New document
Ctrl+I, Ctrl+O Import pictures
Ctrl+S Save
Ctrl+Shift+S Save As
Ctrl+C Copy the page
Ctrl+Z Undo
Ctrl+Y, Ctrl+Shift+Z Redo
Ctrl+L, Ctrl+R Turn the page left or right
Page Up, Page Down Previous or next page
Ctrl+Page Up, Page Down Move the page up or down
Del Delete the page
Alt+D, Alt+T The Device menu and the Settings menu
F5 Look for devices
Ctrl+W Close the window
F1 Help

Command line

scan4win photo1.jpg photo2.jpg
scan4win --demo

Pictures on the command line are imported. --demo is for trying scan4win without a scanner and for screenshots: it has a scanner and a webcam that are made up, and the settings of a first run. The saved settings are not read and not changed.

Install

Download scan4win-<version>-amd64.msi from the releases and run it. It installs scan4win.exe in %LOCALAPPDATA%\Programs\scan4win and adds a "scan4win" shortcut to the Start menu. It installs for the current user only, so it does not need admin rights. Newer versions replace older ones. The installer is signed by Maussoft B.V., see "Code signing" below.

After the install scan4win works in the Run box.

To use it without installing, download scan4win-<version>-amd64.exe instead and run it from anywhere. It is the same program the installer installs. The settings still go to %APPDATA%\scan4win, and Check for Updates opens the download page instead of installing. For Windows on ARM there is scan4win-<version>-arm64.exe, a native build that is only available as a portable exe; the installer works there too, but runs the amd64 build emulated.

Each release has a SHA256SUMS file. To check a download, compare its hash with the one listed there, for example in PowerShell:

Get-FileHash scan4win-<version>-amd64.exe

Code signing

The installer and the exes are signed with a Certum code signing certificate issued to Maussoft B.V. To check, right-click the file in Explorer, choose Properties and open the "Digital Signatures" tab. SmartScreen may still warn about a new release until enough people have downloaded it ("More info", "Run anyway"). Do not run a file that is not signed by Maussoft B.V. The source and the build script are in this repository, so you can also build the exe yourself.

It runs on 64-bit Windows 10 and 11.

Data

Settings are in %APPDATA%\scan4win\settings.json. Pages are kept in memory; nothing of them is written to disk before you save. The only network access is the update check you start yourself.

Build (on Linux)

Install the tools once:

sudo apt install jq wixl msitools wine
go install github.com/tc-hib/go-winres@latest

The icon, manifest (visual styles, DPI awareness) and version info are compiled from winres/ into cmd/scan4win/rsrc_windows_<arch>.syso, which is not committed. run.sh and release.sh generate it.

go test ./...
GOOS=windows go test -exec wine ./internal/wia ./internal/webcam
./run.sh --demo

run.sh builds scan4win.exe and runs it with Wine. Wine has no scanners, so use --demo there. SCAN4WIN_THEME=dark ./run.sh --demo shows the dark colours.

The icon is winres/icon.svg. After changing it, run go run ./tools/genicon (needs Inkscape) to render the PNG files next to it. The icons of the toolbar are Fluent UI System Icons (MIT), in internal/icons/svg.

Release

./release.sh          # 0.1.0 -> 0.1.1 (build, the default)
./release.sh minor    # 0.1.1 -> 0.2.0
./release.sh major    # 0.2.0 -> 1.0.0
./release.sh msi      # only build the MSI of the current version

release.sh needs a clean working tree. It raises the version in winres/winres.json (file_version, as major.minor.build.revision; the revision goes up on every release), runs the tests, builds dist/scan4win-<version>-amd64.msi, the portable dist/scan4win-<version>-amd64.exe and dist/scan4win-<version>-arm64.exe and dist/SHA256SUMS, commits and pushes the version bump and creates the GitHub release with those four files. wixl cannot build an arm64 MSI, so arm64 is only a portable exe. Besides the build tools above it needs the GitHub CLI (gh). The installer is defined in installer/scan4win.wxs. release.sh signs the exes and the MSI with ssctl and the Certum certificate in SimplySign; run ssctl login first and log in with a token from the SimplySign mobile app. SimplySign Desktop is not needed.

Layout

  • internal/scan: the pages, without a user interface and tested on any platform. Finding the paper (detect.go), its size (paper.go), taking the shadows off (clean.go), following the paper and combining pictures of a webcam (watch.go), a page and what can be done with it (page.go), the document with undo (document.go), and PDF and PNG (encode.go).
  • internal/device: what a scanner and a webcam can do. internal/wia has the real scanners, internal/webcam the real webcams (Media Foundation) and internal/demo those that are made up. internal/com calls COM objects.
  • internal/ui: the window. app.go the window and its commands, devices.go scanning, importing and the webcam, canvas.go the page, strip.go the small pages at the left, toolbar.go the toolbar, files.go opening and saving.
  • internal/icons: the icons of the toolbar, drawn from SVG.
  • internal/config, internal/update: settings and the update check.

License

MIT, see LICENSE.

About

Scan to PDF or PNG on Windows with a scanner or a webcam, written in Go

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages