NAME
   Printer::Thermal - Interface for Thermal (and some dot-matrix and
   inkjet) Printers that support ESC-POS specification.

VERSION
   version 0.21

SYNOPSIS
      use Printer::Thermal;

      #For Network Printers $port is 9100 in most cases but might differ depending on how you have configured your printer
      $printer = Printer::Thermal-E<gt>new(device_ip=E<gt>$printer_ip,device_port=E<gt>$port);

      #These commands won't actually send anything to the printer but it will store all the merged data including control codes to send to printer in $printer-E<gt>print_string variable.
      $printer-E<gt>write("Blah Blah \nReceipt Details\nFooter");
      $printer-E<gt>bold_on();
      $printer-E<gt>write("Bold Text");
      $printer-E<gt>bold_off();
      $printer-E<gt>print(); ##Sends the above set of code to the printer. Clears the buffer text in module.

      #For local printer connected on serial port, check syslog(Usually under /var/log/syslog) for what device file was created for your printer when you connect it to your system(For plug and play printers).
      my $path = '/dev/ttyACM0';
      $printer = Printer::Thermal-E<gt>new(serial_device_path=$path);
      $printer-E<gt>write("Blah Blah \nReceipt Details\nFooter");
      $printer-E<gt>bold_on();
      $printer-E<gt>write("Bold Text");
      $printer-E<gt>bold_off();
      $printer-E<gt>print();

      #For local printer connected on usb port, check syslog(Usually under /var/log/syslog) for what device file was created for your printer when you connect it to your system(For plug and play printers).
      my $path = '/dev/usb/lp0';
      $printer = Printer::Thermal-E<gt>new(usb_device_path=$path);
      $printer-E<gt>write("Blah Blah \nReceipt Details\nFooter");
      $printer-E<gt>bold_on();
      $printer-E<gt>write("Bold Text");
      $printer-E<gt>bold_off();
      $printer-E<gt>print();

DESCRIPTION
   Some might not find the module name accurate since ESC-P was developed
   initially for dot matrix and inkjet printers, however today most Thermal
   Receipt Printers use these codes for control. Most people(i.e. like me
   when I started looking for Thermal Printer stuff) who look for Thermal
   Printer codes don't know Thermal Printers use certain set of ESC codes
   to achieve a bunch of functions, and I didn't want to name it
   Printer::ESC::P because that would not help people who are new to
   receipt printers looking for something like this module. This module
   provides an Object oriented interface for interacting with Thermal
   Printers. Maybe I will refactor it later with subclasses. I used Moose
   and I apologize for that!!

   For ESC-P codes refer the guide from Epson
   http://support.epson.ru/upload/library_file/14/esc-p.pdf

ATTRIBUTES
 usb_device_path
   This variable contains the path for the printer device file when
   connected as a usb device on UNIX-like systems. I haven't added support
   for Windows and it probably wont work in doz as a local printer without
   some modifications. Feel free to try it out and let me know what
   happens. This must be passed in the constructor

 serial_device_path
   This variable contains the path for the printer device file when
   connected as a serial device on UNIX-like systems. I haven't added
   support for Windows and it probably wont work in doz as a local printer
   without some modifications. Feel free to try it out and let me know what
   happens. This must be passed in the constructor

 device_ip
   Contains the IP address of the device when its a network printer. The
   module creates IO:Socket::INET object to connect to the printer. This
   can be passed in the constructor.

 device_port
   Contains the network port of the device when its a network printer. The
   module creates IO:Socket::INET object to connect to the printer. This
   can be passed in the constructor.

 baudrate
   When used as a local serial device you can set the baudrate of the
   printer too. Default (38400) will usually work, but not always.

   This param may be specified when creating printer object to make sure it
   works properly.

   $printer = Printer::Thermal->new(serial_device_path => '/dev/ttyACM0',
   baudrate => 9600);

 read_char_time
   *DECRECATED*

 read_const_time
   *DECRECATED*

 black_threshold
   Black ink threshold, This param may be specified when creating the
   printer object. Default is 48.

 alpha_threshold
   Alpha threshold, This param may be specified when creating the printer
   object. Default is 127.

 heatTime
   Heating time to set for Supported Thermal Printers, this affects dot
   intensity.

   This param may be specified when creating the printer object. Default is
   120

 heatInterval
   This param may be specified when creating the printer object. Default is
   50

 heatingDots
   This param may be specified when creating the printer object. Default is
   7

 printer
   This is the direct device handle to the printer, You must almost never
   use this. Unless you are hacking through the module. If you are using
   this you must send me a bug report on why you had to use this.

   You can access it with $printer->printer

 print_string
   This contains the string in the module buffer that will be sent to the
   printer when you call $printer->print();

   my $print_string = $printer->print_string

 font
   Set ESC-POS Font

 underline
   Set/unset underline property

 emphasized
   Set/unset emphasized property

 double_height
   set unset double height property

 double_width
   set unset double width property

METHODS
 print
   $printer->print() Sends the accumulated commands to the printer. All
   commands below need to be followed by a print() to send the data from
   buffer to the printer. You may call more than one printer command and
   then call print to send them all to printer together. The following
   bunch of commands print a text to a printer, move down one line, and cut
   the receipt paper.

       $printer-E<gt>write("hello Printer\n");
       $printer-E<gt>linefeed();
       $printer-E<gt>cutpaper();
       $printer-E<gt>print(); # Sends the all the commands before this to the printer in one go.

 write
   $printer->write("some text\n") Writes a bunch of text that you pass here
   to the module buffer. Note that this will not be passed to the printer
   till you call $printer->print()

 left_margin
   $printer->left_margin($nl,$nh) Sets the left margin code to the printer.
   takes two single byte parameters, $nl and $nh. To determine the value of
   these two bytes, use the INT and MOD conventions. INT indicates the
   integer (or whole number) part of a number, while MOD indicates the
   remainder of a division operation. For example, to break the value 520
   into two bytes, use the following two equations: nH = INT 520/256 nL =
   MOD 520/256

 reset
   Resets the printer

 right_side_character_spacing
   Takes a one byte number, spacing as a parameter

 horiz_tab
   Adds a horizontal tab character like a \t to the print string.

 line_spacing
   Allows you to set the line spacing for the printer.

 linefeed
   Sends a new line character, i.e carriage return and line feed

 justify
   $alignment can be either 'L','C' or 'R' for left center and right
   justified printing

 bold_off
   Turns bold printing off

 bold_on
   Turns bold printing on

 doublestrike_off
   Turns doublestrike on characters off

 doublestrike_on
   Turns doublestrike on characters on

 emphasize_off
   Turns off emphasize(read ESC-POS documentation)

 emphasize_on
   Turns on emphasize(read ESC-POS documentation)

 font_size
   Defined Region 0 ≤ n ≤ 255 However, 1 ≤ vertical direction
   magnification ratio ≤ 8, 1 ≤ horizontal direction magnification
   ratio ≤ 8 Initial Value n=0 Function Specifies the character size
   (magnification ratio in the vertical and horizontal directions).

 font_size_esc
   Set ESC specified font size

       $printer-E<gt>font_size_esc($size);

 font_b
   Switches printing to font b

 font_a
   Switches printing to font a

 underline_off
   Switches off underline

 underline_on
   Switches on underline

 inverse_off
   Switches off inverse text

 inverse_on
   Switches on inverse text

 barcode_height
   Sets barcode height

 print_barcode
   $printer->print_barcode($type,$string) Prints barcode

 print_text
   $printer->print_text($msg,$chars_per_line); Prints some text defined by
   msg. If chars_per_line is defined, inserts newlines after the given
   amount. Use normal '\n' line breaks for empty lines.

 print_bitmap
   To be done: This function is not implemented yet.

 color_1
   Prints in first color for dual color printers

 color_2
   Prints in second color for dual color printers

 cutpaper
   Cuts the paper. Most Thermal receipt printers support the facility to
   cut the receipt using this command once printing is done.

 open_cash_drawer
   Opens the Cash Drawer connected to the thermal printer.

 test
   Prints a bunch of test strings to see if your printer is working
   fine/connected properly. Don't worry if some things like emphasized and
   double strike looks the same, it happened with my printer too.

NOTES
   *   If the printer prints out garbled characters instead of proper text,
       try specifying the baudrate parameter when creating printer object
       when you create the printer object(not for network or USB printers)

        $printer = Printer::Thermal-E<gt>new(serial_device_path => '/dev/ttyACM0', baudrate => 9600);

USAGE
   *   This Module offers a object oriented interface to ESC-POS Printers.

   *   Create a printer object by providing parameters for one of the three
       types of printers supported.

   *   then call formatting options or write() text to printer object in
       sequence.

   *   Then call the print() method to dispatch the sequences from the
       module buffer to the printer.

   Note: While you may call print() after every single command code, this
   is not advisable as some printers tend to choke up if you send them too
   many commands too quickly.

SUPPORT
 Bugs / Feature Requests
   Please report any bugs or feature requests through github at
   <https://github.com/shantanubhadoria/printer-thermal/issues>. You will
   be notified automatically of any progress on your issue.

 Source Code
   This is open source software. The code repository is available for
   public review and contribution under the terms of the license.

   <https://github.com/shantanubhadoria/printer-thermal>

     git clone git://github.com/shantanubhadoria/printer-thermal.git

AUTHOR
   Shantanu Bhadoria ([email protected])

CONTRIBUTOR
   Shantanu Bhadoria <shantanu att cpan dott org>

COPYRIGHT AND LICENSE
   This software is copyright (c) 2013 by Shantanu Bhadoria.

   This is free software; you can redistribute it and/or modify it under
   the same terms as the Perl 5 programming language system itself.