View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Show collection (0 pages)
Collections help

Search

Retail:Developers Guide/How-to/How to Print On Multiple Printers

Contents

Objective

The objective of this article is to explain how to create a Receipt Template that will allow us to print Receipts using several printers at the same time. As we will see, it is also possible to print out different content on each printer.

Recommended articles

Before you continue reading this how-to, we recommend that you read this article: How To Create And Modify New Receipt Documents From Other Modules, which explains how to create new Receipt Templates within our module so that they are used when printing from WebPOS.

Execution Steps

  1. Obviously, the first step is to configure the Hardware Manager so that you can print on several printers simultaneously. To do so we have to modify the file "openbravohw.properties" and add the printers we want to use. In this example, we will use the screen printers that are offered by the Hardware Manager:
 machine.printer = screen
 machine.printer.2 = screen
 machine.printer.3 =
  1. The next step consists of editing the xml file for our Receipt Template. The following xml code shows an example of how to print in two printers simultaneously:
    <?xml version="1.0" encoding="UTF-8"?>
    <output>
      <ticket printer="1">
        <line>
            <image>ticket-image.png</image>
        </line>
        <line>
          <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent('This is')%></text>
        </line>
        <line>
          <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent('a customized receipt for printer 1')%></text>
        </line>
      </ticket>
      <ticket printer="2">
        <line>
            <image>ticket-image.png</image>
        </line>
        <line>
          <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent('This is')%></text>
        </line>
        <line>
          <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent('a customized receipt for printer 2')%></text>
        </line>
      </ticket>
    </output>
    To specify the printer, we use the printer tag and assign a value to it. This value defines the printer number according to the Hardware Manager configuration.

  2. Moreover, it is possible to dynamically assign the printer number. So we can also dynamically choose which printer to print with, depending on our business logic.
    <?xml version="1.0" encoding="UTF-8"?>
    <output>
      <%
        var lines = order.get('lines'),line,printer = 1;text='does not contain';
        for (var i = 0; i < lines.length; i++) {
          line = lines.at(i);
          var prodname = line.get('product').get('_identifier').toString();
          if (prodname == "Vino Tinto 0,75L"){
            printer = 2;
            text = 'contains';
            break;
          }
        }
      %>
      <ticket printer = "<%= printer %>">
        <line>
            <image>ticket-image.png</image>
        </line>
        <line>
          <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent('This receipt')%></text>
        </line>
        <line>
          <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent(text+' Vino Tinto 0,75L')%></text>
        </line>
      </ticket>
    </output>
     

    What this piece of code does, is going through the products listed in the Receipt and prints the Receipt using printer #2 if one of them is "Vino Tinto 0,75L".If that is not the case, it prints the Receipt using printer #1.

Result

Following screenshots show the results after successfully carrying out the steps mentioned above:

This screen show the customized Receipt being printed on printer #2:

View larger

And this one shows the printers using the code sample for dynamic Receipt content:

View larger

Retrieved from "http://wiki.openbravo.com/wiki/Retail:Developers_Guide/How-to/How_to_Print_On_Multiple_Printers"

This page has been accessed 2,328 times. This page was last modified on 26 April 2013, at 11:56. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.