Initial PrintBridge implementation: Windows tray app for web-to-printer - #1
Merged
Merged
Conversation
PrintBridge is the printing sibling of ScanBridge: a Windows tray app with a loopback-only HTTP API that web pages POST a PDF to, which is then rendered and handed to the Windows print spooler with no dialog and no user interaction. Mirrors ScanBridge's structure — settings store, Kestrel host, tray context, code-built settings window, job manager with polling — with the differences the print direction implies: - Named queues. Administrators map a queue name to a Windows printer; callers only ever use the name, so the printer behind a queue can be swapped without touching a web app and no caller learns the machine's printer names. - FIFO drain loop instead of a busy rejection. Submissions are always accepted and printed one at a time, which bounds the memory cost of rendering pages at printer resolution. - PDFtoImage (PDFium + SkiaSharp, MIT/BSD-3) rasterizes each page lazily at the printer's own resolution; System.Drawing.Printing spools it, with StandardPrintController for silent printing, per-page orientation from the PDF and scale-to-fit-never-enlarge centering. The API is documented in docs/api.md: status, queues, submit (raw PDF body plus ?queue=&copies=), poll, cancel. Tests cover queue resolution, the PDF sniffer, job manager behaviour, page fitting math and the settings round-trip. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Ym9ifwDcWhR56pTn6BZzd
Two fixes after the first CI run (which built clean and failed one test): - Page placement measured PageSettings.PrintableArea and swapped it by hand for landscape pages. The .NET implementation already swaps that value itself, and which way it lands depends on the driver, so the workaround was a coin flip. Graphics.VisibleClipBounds comes straight from the printer device context and is therefore in the page's real orientation whatever the driver does; PageBounds (verifiably orientation-aware) stays as the fallback. FitCentered now takes the area as a rectangle so a non-zero clip origin is honored. - JobsAreDrainedInSubmissionOrder waited for the job status to turn "printing", which the manager sets just before it calls the executor — so the assertion could run before the executor recorded anything. It now waits on the executor's own record. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Ym9ifwDcWhR56pTn6BZzd
The queue editor already checks the installed-printer list itself when it has to show a queue whose printer is gone, so nothing calls this. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Ym9ifwDcWhR56pTn6BZzd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the initial implementation of PrintBridge, a Windows tray application that enables web applications to print to desktop printers via a local HTTP API.
Summary
PrintBridge provides a bridge between web browsers and Windows printers. Web applications POST PDF documents to a local HTTP API (default port 7227), and PrintBridge silently renders and spools them to configured printers without user interaction. Administrators configure named print queues (mapping queue names to Windows printers) and allowlist website origins that can access the API.
Key Changes
PrintService.cs): Renders PDF pages at printer resolution using PDFium (via PDFtoImage) and hands them to the Windows spooler withStandardPrintControllerfor silent printingPrintJobManager.cs): In-memory registry that queues jobs FIFO, executes them serially to bound memory usage, and retains terminal jobs for browser observationApiEndpoints.cs,WebHostRunner.cs): ASP.NET Core Kestrel listener bound to 127.0.0.1 with CORS enforcement, supporting/api/v1/status,/api/v1/queues, and/api/v1/print-jobsendpointsSettingsStore.cs,AppSettings.cs): JSON-based configuration for queues, port, allowed origins, and run-at-login preference with atomic writesSettingsForm.cs,QueueEditDialog.cs,TrayApplicationContext.cs): WinForms-based settings window and tray icon menu, built in code rather than designer for reviewabilityNotable Implementation Details
StandardPrintControllerinstead of the default controller to suppress print dialogsunknownQueue,invalidDocument, etc.) for API clientshttps://claude.ai/code/session_013Ym9ifwDcWhR56pTn6BZzd