I'm trying to print to Dot Matrix printers (various models) out of C#, currently I'm using Win32 API (you can find alot of examples online) calls to send escape codes directly to the printer out of my C# application. This works great, but...
My problem is because I'm generating the escape codes and not relying on the windows print system the printouts can't be sent to any "normal" printers or to things like PDF print drivers. (This is now causing a problem as we're trying to use the application on a 2008 Terminal Server using Easy Print [Which is XPS based])
The question is: How can I print formatted documents (invoices on pre-printed stationary) to Dot Matrix printers (Epson, Oki and Panasonic... various models) out of C# not using direct printing, escape codes etc.
**Just to clarify, I'm trying things like GDI+ (System.Drawing.Printing) but the problem is that its very hard, to get things to line up like the old code did. (The old code sent the characters direct to the printer bypassing the windows driver.) Any suggestions how things could be improved so that they could use GDI+ but still line up like the old code did?
You should probably use a reporting tool to make templates that allow you or users to correctly position the fields with regards to the pre-printed stationery.
Using dot-matrix printers, you basically have to work in either of 2 modes:
The first usage is mostly deprecated under Windows as it does not offer much in the way of controlling the output, and each printer having its own characteristics it becomes unwieldy and difficult for the software to predict and position things on the page (no WYSIWYG).
The second just uses a graphic page paradigm that makes positioning text and graphics independent of the actual capabilities of the printer.
When using pre-printed stationery, your job s to correctly position the data on the page.
Doing this by hand is resource-consuming and creating the layout in code is certainly not recommended since you'll get stuck with code to change should your printer, page format or printed stationery change.
The best is to just use the standard printing model offered by .Net and a reporting tool that allows you to define models and templates where the correct text and graphics will be positioned, and then drive this from code.
Visual Studio is shipped with a version of Crystal Reports but there are other, better reporting systems (I use the one from developer express for instance), some of them are even free.
From my experience, it is easier to use two kinds of reports for the same data:
type file.txt > lpt1
or selecting in code the default printer and using NOTEPAD /P file.txt
) - see this page for more printing methods. Since it is not uncommon to buy the right kind of printer for the right kind of report, this approach has the advantage of letting the customer decide: dot matrix printer for text reports in A3/A4 paper format (usually for the accounting department) or laser/inkjet printer for graphical reports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With