Dot Matrix printing in C#?

前端 未结 8 2055
南笙
南笙 2020-12-13 08:03

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 dire

相关标签:
8条回答
  • 2020-12-13 08:12

    You can refer this http://www.codeproject.com/Articles/29709/Line-Printer-Class-in-C hope helpd

    0 讨论(0)
  • 2020-12-13 08:14

    Take a look at the System.Drawing.Printing namespace.

    0 讨论(0)
  • 2020-12-13 08:17

    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:

    • simple type-writer mode of line/column text where you send escape sequences to manage a small number of fonts that are included in the printer hardware and have to manage line returns, etc.
    • graphic output where the page is rasterized and the printer driver just drives the print head and pins to output the dots.

    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.

    0 讨论(0)
  • 2020-12-13 08:20

    i don't know how to use Escape sequence in C#. But i have all Escape Sequence for Generic / Text Only printer. Hope it helps.

    Generic Print Escape Sequence 1) Set Line Spacing a) 1/8 inch - 27,48 b) 1/6 inch - 27,50

    2) Select Draft Quality a) 27,120,0 / 27,120,48

    3) Letter Quality a) 27,120,1 / 27,120,49

    4) Double Height a) 27,119,n i) n = 1 On ii) n = 0 Off

    5) Bidirectional Printing a) 27,85,n i) 0 - Both Way ii) 1 - One Way

    6) Increase character space a) 27,32,n (Increase by n / 12 inch)

    7) Select Bold Font a) 27,69

    8) Cancel Bold Font a) 27,70

    9) Select Italic Font a) 27,52

    10) Cancel Italic Font a) 27,53

    11) Select a) 10cpi 27,8 b) 12cpi 27,77 c) 15cpi 27,103 d) 18cpi 27,103

    12) Set Right Margin a) 27,81,n

    13) Set Left Margin a) 27,108,n

    14) Form Feed a) 12

    15) Condensed Printing a) 0F On b) 12 Off

    16) Double Strike Printing a) 27,71

    17) Cancel Strike Printing a) 27,72

    18) Under line a) 27,45,0 Off b) 27,45,1 On

    19) Double Width a) 27,84,0 Off b) 27,84,1 ON

    0 讨论(0)
  • 2020-12-13 08:30

    From my experience, it is easier to use two kinds of reports for the same data:

    • one report for dot matrix printers using escape codes and anything else is required, which is saved in a text file and then printed using various methods (type file.txt > lpt1 or selecting in code the default printer and using NOTEPAD /P file.txt) - see this page for more printing methods.
    • another report for laser/inkjet printers using a report builder tool (Crystal Reports, Report Manager, RLIB or anything available)

    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.

    0 讨论(0)
  • 2020-12-13 08:34

    If your printer has driver to install, then you can use normal Windows print system. Most printers, including POS ones, have working Windows drivers available. (Most dot-matrix printers are Epson compatible anyway.) Some POS printer drivers allow send escape codes directly to printer too (using special fonts); probably you don't need such functionality.

    If this is not the case, then you can add Generic/Text Only printer (driver) with help of Add Printer Wizard. Once done, you can configure certain commands (escape sequences) for it - Font size 10/12/17, Bold on/off, Underline on/off, job start/stop, paper feed and size select.

    I'm using Generic printer associated with FILE port to test various reports for POS printers - it's easy to look at text file to validate numbers in printout. Of course for formatting specific printer driver is needed.

    0 讨论(0)
提交回复
热议问题