Printing in Windows Service - Idea
First, let me say I’m probably crazy…
I have an older program at work that (among its many functions) prints packing lists containing details of the shipment as well as our company’s logo and a barcode for a verification step. The application is a Windows WinForms desktop application written in C#.NET. The printing is accomplished using the System.Drawing.Printing.PrintDocument class and is fairly basic. It was recently requested that we basically put the application on a server so that one of our web applications can print these documents. I said probably… How hard can it be? If any of you have been down this path, you know that both WPF and WinForms printing do not work consistently in either a Windows service or web application so I was in for a rough time. I eventually decided to scrap the code that performs the printing in favor of building that a little closer to “the metal” in GDI and winspool.
C# interop, Go, C++, C, or… D?
I finally decided, and I think I am choosing to do this project in D. I probably should stick with C# (since I know it very well… even the interop stuff I would need), but that seems too easy and I also would like it to not be dependent on the .NET framework being installed. It’s been years since I made anything more than a toy in C++, and I really like the new C++ 11/17/20 features in the language, but it would’nt make sense to use many of those features since this project would mostly be interactions with Windows APIs. I have always liked D (never found a project that really needed it though). It is every bit as low level and C and C++ but with many of the nicer qualities of C# (this is of course my perspective and not that of my peers). This will involve linking to external C libraries and I found my guide in Charles Petzold’s Programming Windows book, translated by Andrej Mitrovic.
This is going to be fun!
Project Scope
I want to keep the application as simple as possible. A console application that accepts 3 arguments and has some minor configuration options in a related file.
Arguments:
- file_path: (path to text file containing the packing list contents)
- logo_path: (path to file with image of company logo)
- barcode_value: (string contents for header barcode)
Configuration:
App will have defaults for these items in case file not loaded or available
- Page
- Margins: 10 x 10 x 10 x 10
- Font: Courier (12pt)
- Landscape: true
- Logo
- Size: height|width
- Left: true
- Barcode
- Size: height|width