Better ticket printing experience, released by huanent. printer2.0 and huanent. printer2.0

Source: Internet
Author: User
Tags print object

Better ticket printing experience, released by huanent. printer2.0 and huanent. printer2.0

Huanent. printer2.0 is a class library that focuses on printing small tickets. With many advanced features, such as center printing and automatic line feed, you can print complex consumption receipts with simple code. Huanent. printer is authorized by MIT and can be used for commercial purposes at will. You only need to specify the author.

You can get source code through github and submit bugs: https://github.com/huanent/Huanent.Printer

The huanent. printer has been uploaded to nuget. You can search for the name huanent. printer in nuget to install it.

The following three images use huanent. printer prints, 76, and 58 small tickets with different widths. You only need to switch one attribute value to automatically adapt to the issue. In the title play, the product name is too long and the length of the split line is adaptive.

The use of huanent. printer is also very simple. First, obtain the name list of all the printers on the computer.

var printers = PrintQueueHelper.GetPrintQueueName();

Select your invoice printer name from printers and use this name to obtain an IPrinter Print Object

var printer = PrinterFactory.GetPrinter("xp80mm", PaperWidth.Paper80mm);
The second parameter of GetPrinter can be used to input a PaperWidth enumeration, Which is predefined to 80, 76, and 58 widths, or a custom int value.
The IPrinter object has five methods:
  • PrintText
  • PrintImage
  • PrintLine
  • NewRow
  • Finish
PrintText Method
The PrintText method can flexibly specify the text printing mode, for example, the text playing mode. The left, middle, and right alignment can be performed (you must call the Finish () method to start printing !)
Printer. PrintText ("hello", stringAlignment: StringAlignment. Center); printer. PrintText ("Hello 2", stringAlignment: StringAlignment. Far); printer. Finish ();

You can specify the maximum width of the text. If the text exceeds the width, it will automatically wrap the text. The value range of width is 0 to 1, and 0.3 represents 30 percent of the width of the paper.

Printer. PrintText ("February 5, 6, 7, 80 or 90, 80 or 90, 80 or 90,", width: 0.3f); printer. Finish ();

 

Specified offset

Printer. PrintText ("February 5, 6, 7, 80 or 90, 80 or 90, 80 or 90,", width: 0.3f, offset: 0.2f); printer. Finish ();

Specify the font size (the NewRow () method must be called to display the font size)

Printer. printText ("zheng", Printer. models. fontSize. huge); printer. newRow (); printer. printText ("positive"); printer. newRow (); printer. printText ("zheng", Printer. models. fontSize. micro); printer. newRow (); printer. finish ();

PrintImage Method

Print an image and the image can be aligned.

printer.PrintImage(new Bitmap("qr.png"),StringAlignment.Far);printer.Finish();

PrintLine Method

PrintLine prints a line. We recommend that you use this method if you want to print the split line on the ticket, instead of using PrintText. Because PrintLine can adapt the line width of different paper without leading to line breaks

printer.PrintLine();printer.Finish();

 

NewRow Method

Calling the NewRow method will cause a line feed. Even if a PrintText contains multiple lines, it can be intelligently wrapped.

Printer. printText ("1234", width: 0.3f); printer. printText ("May 1234", width: 0.2f, offset: 0.4f); printer. newRow (); printer. printText ("I am a new line"); printer. newRow (); printer. finish ();

Finish Method

The Finish method is very simple. After all the above methods are called, they are in the buffer zone. After calling Finish, the bill is printed on the invoice machine and the buffer zone is cleared. So you can call it at the end of the ticket code.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.