Kovu's terrasco.net
 Autologin
KEscPos Functions/Class Reference
 
Author: Kovu | Date: Feb 05 2010
 
This is the official functions/class reference file for Kovu's KEscPos printer driver.
Code:
  
  #############################################
  #                                           #
  #                 KEscPos                   #
  #     Kovu's ESC/POS Printer Driver v1.0    #
  #       Functions / Class Reference         #
  #                                           #
  # (c) Markus Fumagalli "Kovu", terrasco.net #
  #              January 5 2010               #
  #                                           #
  #############################################
  
  
  1) SUPPORTED PRINTERS
     
     Any receipt printer that follows the Epson ESC/POS standards.
     Developed for and tested with Epson TM-U220B, Epson TM-T88IV.
     The most basic features can be adjusted for your printer by
     adding it to the $KEscPos_printer array, defined in the first
     lines of the kescpos.drv.php file. Alternatively you can add
     the required index and data to the array after loading the
     driver file.
     
  
  2) WHAT HAS CHANGED SINCE THE OLD DRIVER FILES?
     
     You no longer need to write a driver file for every printer
     model you have. You can simply add them to the $KEscPos_printer
     array. Further, KEscPos is object oriented, for easy usage.
     While you need to rewrite your printer code when switching to
     KEscPos, I can assure you it's worth spending those minutes -
     because KEscPos comes with various additional features, such as:
     
     -> Image Printing (as long as PHP-GTK or GD are installed) [Kovu]
     -> BarCode Printing [Kovu]
     -> Upside Down Printing [Smacedo]
     -> Select Character Size [Smacedo]
     -> Inverted B/W Printing (Black / White switch) [Kovu]
     -> Print File [Solis / Kovu]
     
  
  3) CONSTANTS & PRESET VARS
  
     Printer setups:
        
        $KEscPos_printer  (array)
        
           Predefined printers:
              
              'TM-U220B AFU'
              'TM-T88IV AFU'
     
     
  4) GLOBAL FUNCTIONS
     
     ===============
     ¦ kbyte($val) ¦
     ===============
     
     Serves as a cast for byte values. Similar to chr().
     
     
  5) PRINTER HANDLING
     
     ============================
     ¦ $escpos = new KEscPos(); ¦
     ============================
     
     Sets up a blank KEscPos object.
     
     
     =============================================================================
     ¦ $escpos = new KEscPos($printer_setup, $printer_name, $reset, $com_setup); ¦
     =============================================================================
     
     Opens a printer directly. $printer_setup asks for the setup to select
     from the $KEscPos_printer array. $printer_name either defines the name
     with which a printer is called in a printer system, or the port
     to which the printer is connected. $reset will reset the printer at 
     opening time. $com_setup defines if a port's settings have to be changed 
     as it's been specified in the $KEscPos_printer array. $com_setup and
     $reset default to true.
     
     
     ====================================
     ¦ $escpos -> UseTranslation($use); ¦
     ====================================
     
     Use KEscPos Character Translation? $use takes bool true or false.
     
     
     ========================================================
     ¦ $escpos -> TranslationSetup($name, $find, $replace); ¦
     ========================================================
     
     Sets up a character translation table. $name defines the name that
     is displayed for reference, whereas $find and $replace hold arrays
     that will be stored in the KEscPos object.
     
     
     ==================================================
     ¦ $escpos -> PrinterCharacterTable($char_table); ¦
     ==================================================
     
     Select the printer's character table.
     
     
     ================================
     ¦ $escpos -> SetWidth($width); ¦
     ================================
     
     Set the width (space available on the paper as characters).
     
     
     ===================================================================================================================
     ¦ $escpos -> CapSetup($set_color, $set_barcode, $set_cut, $set_logo, $set_drawer, $set_fontselect, $set_reverse); ¦
     ===================================================================================================================
     
     Defines what your printer actually can do. Each argument takes bool false or 
     true.
     
     $set_color:       printer can change color
     $set_barcode:     printer can print bar codes
     $set_cut:         printer has a cutter
     $set_logo:        printer can print logos
     $set_drawer:      printer can generate a drawer kick signal
     $set_fontselect:  printer can select fonts
     $set_reverse:     printer can reverse feed
     
     
     ================================================================================
     ¦ $escpos -> ComSetup($set_baud, $set_parity, $set_data, $set_stop, $set_xon); ¦
     ================================================================================
     
     Defines how to setup the port for communication with your printer.
     Values should follow the mode command standard from DOS/WINDOWS.

     $set_baud:      BAUD
     $set_parity:    PARITY BIT
     $set_data:      DATA BIT
     $set_stop:      STOP BIT
     $set_xon:       XON/XOFF
     
     
     ===================================
     ¦ $escpos -> LoadSetup($printer); ¦
     ===================================
     
     Loads a setup from the $KEscPos_printer array if it exists.
     
     
     ============================================
     ¦ $escpos -> GetSettings($setting, $echo); ¦
     ============================================
     
     Echoes or returns the current settings of the KEscPos object. If 
     $echo is true, GetSettings() will send the results to output directly.
     If $setting isn't false and exists, GetSettings() will output its value.
     If $setting is false, GetSettings() will output all settings in an array.
     
     
     =======================================================
     ¦ $escpos -> Open($printer_name, $reset, $com_setup); ¦
     =======================================================
     
     $printer_name either defines the name with which a printer is called in a 
     system printing tool, or the port to which the printer is connected. $reset 
     will reset the printer at opening time. $com_setup defines if a port's 
     settings have to be changed as it's been specified with ComSetup(). 
     $com_setup and $reset default to true.
     
     
     ========================
     ¦ $escpos -> Output(); ¦
     ========================
     
     Send the buffer and print it. Output() resets the document after a
     succesfull write.
      
     
     =======================
     ¦ $escpos -> Close(); ¦
     =======================
     
     Sends and prints the buffer, closes the printer connection and resets 
     the document. 
     
     
  6) DOCUMENT MANIPULATION
     
     =============================
     ¦ $escpos -> Color($color); ¦
     =============================
     
     Select color.
     
     $color (integer) 0 or 1
     
     
     ======================================
     ¦ $escpos -> Double($double_strike); ¦
     ======================================
     
     Turn double strike mode on or off.
     
     $double_strike (bool) true or false
     
     
     ==================================
     ¦ $escpos -> Emphasize($select); ¦
     ==================================
     
     Turn emphasized mode on or off.
     
     $select (bool) true or false
     
     
     =====================================
     ¦ $escpos -> Underline($underline); ¦
     =====================================
     
     Turn underlined mode on or off.
     
     $underline (bool) true or false
     
     
     ===============================
     ¦ $escpos -> InvertBW($side); ¦
     ===============================
     
     Invert Black / White.
     
     $side (integer) 0 or 1
     
     
     =================================
     ¦ $escpos -> UpsideDown($side); ¦
     =================================
     
     Print upside down.
     
     $side (integer) 0 or 1
     
     
     ===========================
     ¦ $escpos -> Size($size); ¦
     ===========================
     
     Set character size.
     
     $size (integer) 0 - 255
     
     
     ===========================
     ¦ $escpos -> Font($font); ¦
     ===========================
     
     Select font.
     
     $font (string) 'A', 'B' or 'C'
     
     
     =============================
     ¦ $escpos -> Height($size); ¦
     =============================
     
     Select character height.
     
     $size (string) 'double' or 'normal'
     
     
     ============================
     ¦ $escpos -> Width($size); ¦
     ============================
     
     Select character width.
     
     $size (string) 'double' or 'normal'
     
     
     ================================
     ¦ $escpos -> Align($position); ¦
     ================================
     
     Select alignment.
     
     $position (string) 'left', 'center' or 'right'
     
     
     ====================
     ¦ $escpos -> NL(); ¦
     ====================
     
     Go to a new line (1 linefeed).
     
     
     =============================
     ¦ $escpos -> XFeed($lines); ¦
     =============================
     
     Feed X lines. Note: on certain printers this function might lead
     to unexpected behavior. XFeed() will override settings above 2
     with 2.
     
     $lines (integer) 1 or 2
     
     
     ==============================
     ¦ $escpos -> XrFeed($lines); ¦
     ==============================
     
     Reverse feed X lines. Note: on certain printers this function
     might lead to unexpected behavior. XrFeed() will override settings 
     above 2 with 2.
     
     $lines (integer) 1 or 2
     
     
     ===========================
     ¦ $escpos -> Cut($lines); ¦
     ===========================
     
     Feed X lines and cut the paper.
     
     $lines (integer)
     
     
     ============================
     ¦ $escpos -> Drawer($pin); ¦
     ============================
     
     Send drawer kick signal at $pin. If $pin is string 'both',
     Drawer() will execute twice for pin 2 and 5. Otherwise:
     
     $pin (integer) 2 or 5
     
     
     ====================================
     ¦ $escpos -> Line($string, $feed); ¦
     ====================================
     
     Send text (stored in $string). $feed defines if Line() has 
     to do a line feed after the text.
     
     $string (string) text
     $feed   (bool)   true or false
     
     
     ======================================
     ¦ $escpos -> File($path, $textmode); ¦
     ======================================
     
     Reads a text file and prints its content. $textmode defines
     if File() will read line by line (with character translation)
     or send the contents directly. If $textmode is false, the file
     contents are used as raw string and sent to the printer in an
     unmodified form.
     
     $path     (string) textfile path
     $textmode (bool)   true or false
     
     
     ===========================================================
     ¦ $escpos -> BarcodeSetup($width, $height, $text, $font); ¦
     ===========================================================
     
     Prepare barcode for processing and printing.
     
     $width  (integer) barcode width
     $height (integer) barcode height
     $text   (string)  position: 'none', 'above', 'below' or 'both'
     $font   (integer) barcode font
     
     
     ====================================================
     ¦ $escpos -> Barcode($barcode, $system, $n_chars); ¦
     ====================================================
     
     Select barcode system and print.
     
     $barcode (integer) barcode number
     $system  (string)  'UPC-A', 'UPC-E', 'JAN13', 'EAN13', 'JAN8', 'EAN8', 
                        'CODE39', 'ITF', 'CODABAR', 'NW7', 'CODE93', 'CODE128'
     $n_chars (integer) number of characters transmitted
     
     
     ========================================
     ¦ $escpos -> Image($bit_array, $path); ¦
     ========================================
     
     Print an image from a bit array or image file. If $bit_array is false,
     Image() assumes it has to create its own bit array from an image file.
     $path isn't needed if there's a valid $bit_array. Note: bit array
     generating only works if PHP-GTK or PHP's GD is installed and loaded.
     Further, don't send bit array data that is too large. Resize your
     image file before using it (at maximum sizes around 450px X 450px) and
     preferably chose monochrome image data to process.
     
     $bit_array (BitArrayGD / BitArrayGTK) bit array
     
     or
     
     $path      (string)                   path to image file (png, jpg, bmp)
     
     
  7) CREATING BIT-ARRAYS
     
     =======================================
     ¦ $bit_array = new BitArrayGtk($path) ¦
     =======================================
     
     This class is only available when PHP-GTK is installed and loaded.
     Further, don't use images that are too large. Resize your image file 
     before using it (at maximum sizes around 450px X 450px) and preferably
     chose monochrome image data to process.
     
     
     ======================================
     ¦ $bit_array = new BitArrayGD($path) ¦
     ======================================
     
     This class is only available when PHP's GD is installed and loaded.
     Further, don't use images that are too large. Resize your image file 
     before using it (at maximum sizes around 450px X 450px) and preferably
     chose monochrome image data to process.