Plenusco Mobile Print Service (PMPS)

http://www.plenusco.com
Plenusco Mobile Print Service (PMPS)
Most of the application developers are facing an issue when they want to use printing in
mobile. It require to install supporting driver, many printers don’t support mobile
platform…etc. The Plenusco Mobile Print Service (PMPS) addressed this issue by introducing
generic application that can be used with your application where web/native android.
Epson ESC/P protocol supports many printers in industry.
Some of Epson printers are below
TM-J2000, TM-J2100, TM-L90, TM-P60, TM-P60II, TM-P80, TM-T20, TM-T20II, TM-T70, TMT70II, TM-T82II, TM-T88IV, TM-T88V, TM-T90, TM-U220, TM-U230
Some of Zebra models
Zebra iMZ220, iMZ320
The Plenusco Mobile Print Service can be used securely enable authorized web pages to make
printouts directly from Android phones using printers that support Epson ESC/P protocol.
Therefor no driver installation required in device. This can be used to develop mobile web
applications that can print invoices, recites, etc... using a portable POS printer.
PMPS expose a simple REST endpoint with CORS support to enable web pages to directly
submit print jobs to it. However this endpoint is secured by an HTTP ‘Authorization’ header.
In order for the application to print using this service the mobile user should manually read
this key and provide it to the web application.
PMPS
Your Application
Plenusco Print
Server
Plenusco TML
Engine
EPSON ESC/P
Engine
HTTP POST
Steps for setting up PMPS
1. Get the PMPS from Google Play store
2. Connect your printer to network. Printer can be wifi printer or with LAN port.
Once you connect your printer to network, printer is assigned with IP address.
Note: Your printer should support EPSON ESC/P.
3. Open PMPS in your android device. You will see below UI.
4. First of all you need to register the printer that you have connected to same wifi
network. Click the “Register” button
5. Enter the printer IP address as below. In your case, IP may be different.
(If you need to find out your printer IP from your PC, login to the router and find out
the IP)
6. Select the Device Type. If your printer has LAN port and connected to local network
using cable or printer support wife , select device type as TCP(wife). If the printer
has Bluetooth select the Bluetooth and select USB for direct USB support.
7. Click on “Register” button, once registration successful, you will see below screen
with register button is disabled. If the registration is failed, you will get a error
message.
Note: Registration can be failed due to cable unplug, IP address is wrong or printer
does not support EPSON ESC/P.
8. Now you are ready to do test print. Click on “Printer Test”. You will see below screen
9. Click on “Print” button then you will see below screen and check your print out in
printer. You should get text invoice printer out.
10. If you have executed until steps 9 mean your printer is ready to use for your
application. Go back to main screen by clicking back.
11. Before link with your application, you can fully test and understand how to call REST
service. GO to the sample HTML page which has been deployed by Plenusco. Go to
device web browser and enter b=following URL
http://print.azurewebsites.net/print.html
12. You need to enter the “secret key” which is HTTP ‘Authorization’ header.
Go to the application and copy the “Authorization code” as below.
In this example it is 44932
13. Enter paper width that you want. By default it is 80 mm.
14. Go to web browser that you already opened and enter “secret Key“ that you can see
on PMPS mail page. (e.g. 44932)
15. You can see sample TML string on the web page. You can print any type of text by
modifying TML. In this example, you can print sample TML string. Click on “Print”
button. You should be able get print put
Points:
1. You have not installed any printer driver. It does not matter whether printer
support android or not. As long as printer support Epson ESC/P, plenusco
enable you to print easily.
2. Your invoices / receipts can be any size. PMPS has TML engine which does
printing when you pass any type of TML data.
3. Your application can be web application or native android application. You
need to call REST service so PMPS will print for you.
For Developers.
In the above steps 11 to 15 you have executed with sample web page. Now you may need
to integrate with your application. Here are the points
1. Use HTTP POST and send data to PMPS.
The below sample code shows how to call PMPS from a web page using a JavaScript
(jQuery),
function print(secretKey, tmlMessageToPrint) {
var printingServiceUrl = "http://localhost:8080/";
$.ajax({
url: printingServiceUrl,
data: tmlMessageToPrint,
type: "POST",
beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', secretKey); }
})
.done(function () {
alert("Sent to the Printer Service");
})
.fail(function( jqXHR, textStatus ) {
alert( "Request failed: " + textStatus );
});
}
Note: you need to send “secretKey”. This key will be regenerated when you close PMPS and
reopen. So you need to keep easy way that you can change it.
Above example is REST service. You can use any other way based on your
development methodology where you need to call HTTP POST with authorization header.



var printingServiceUrl = "http://localhost:8080/"; is PMPS URL in your device
data: tmlMessageToPrint = TML data that you want to print.
'Authorization', secretKey = Authorization header code
2. For this JavaScript to work, the web page hosting it must be authorized to access an
external web site sing CORS protocol. This can be done by adding the below HTTP
header to the response message of this page,
Access-Control-Allow-Origin : <print server URL> or * (for all sites)
e.g.
Apache:
Add the following line inside either the <Directory>, <Location>, <Files> or
<VirtualHost> sections of your server config (usually located in a *.conf file, such as
httpd.conf or apache.conf), or within a .htaccess file:
Header set Access-Control-Allow-Origin "*"
IIS:
Add the below configuration setting into the web.config file,
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
3. TML data
The content to be printed should be written using a mark-up language called TML (Text
Markup Language) . This simple markup language that looks similar to HTML enables the
applications to define the layout of the printed contents in a format this is independent of
the printer width.
TML A sample TML document is shown below,
<?xml version="1.0" encoding="utf-8"?>
<tml>
<table>
<tr>
<td align='center' width='100%'>Invoice 1</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td mode='fill'>_</td>
</tr>
</table>
<table>
<tr>
<td>Code </td>
<td width='*'>Description</td>
<td align='right'>Qty</td>
<td align='right'>Unit Price</td>
<td align='right'>Price</td>
</tr>
<tr>
<td colspan='5' mode='fill'>_</td>
</tr>
<tr>
<td >A1</td>
<td mode='wrap' width='*'>AAA AAA aasdf asdf FF DDDDD
<td align='right'>2</td>
<td align='right'>20.00</td>
<td align='right'>40.00</td>
</tr>
<tr>
<td>B1</td>
<td mode='wrap' width='*'>BB BB</td>
<td align='right'>1</td>
<td align='right'>30.00</td>
<td align='right'>30.00</td>
</tr>
<tr>
<td colspan='5' mode='fill'>_</td>
</tr>
<tr>
<td colspan='4'>Total</td>
<td align='right'>70.00</td>
</tr>
</table>
</tml>
WWW FF</td>
Output (on 50 character wide printer) would look like below
Note:
Root tag of the TML document should be tml
TML document is a collection of tables. These tables are defined using very similar markups
as HTML,
e.g. ‘<table>’, ‘<tr>’ and ‘<td>’ elements are used with the same meaning. ‘colspan’
and ‘algin’ attribute can be used in td element for the same purpose as HTML.
width attribute on td element Integer - width of the column in number of characters (e.g. 20)
 Percentage - a percentage of the total width (e.g. 20%)
 * - stretch the column to fill the remaining space (if multiple columns has this
attribute then all columns will be of equal size
 not specified - If the width attribute is not present, then the column size will be
adjusted to the size of the maximum text content of that column + 1
mode attribute on td element  wrap - wrap text if the column is not wide enough
 trim - trim the text if the column is not wide enough
 fill - fill the column by repeating the text
Unlike HTML tables these tables does not have borders, margins or paddings
4. Above TML will be printed like below