NAME
XML::Printer::ESCPOS - An XML parser for generating ESCPOS output.
DESCRIPTION
This module provides a markup language that describes what your ESCPOS printer should do. It works on top of the great and easy to use Printer::ESCPOS. Now you can save your printer output in an XML file and you can write templates to be processed by Template Toolkit or the template engine of your choice.
SYNOPSIS
use Printer::ESCPOS;
use XML::Printer::ESCPOS;
# connect to your printer, see Printer::ESCPOS for more examples
my $device = Printer::ESCPOS->new(
driverType => 'Network',
deviceIp => '192.168.0.10',
devicePort => 9100,
);
my $parser = XML::Printer::ESCPOS->new(printer => $device->printer);
$parser->parse(q#
<escpos>
<bold>bold text</bold>
<underline>underlined text</underline>
</escpos>
#) or die "Error parsing ESCPOS XML file: ".$parser->errormessage;
$device->printer->cutPaper();
$device->printer->print();
METHODS
new(printer => $printer)
Constructs a new XML::Printer::ESCPOS object. You must provide a printer object you get by Printer::ESCPOS-
new(...)->printer>.
If you do not set a printer, the module works in debug mode (see below).
parse($xml)
Parses the XML data given by $xml
. $xml
should contain the file content. Returns 1 on success, undef otherwise. If parsing was unsuccessful, you can find the errormessage by calling the errormessage
method.
errormessage
Returns the last error message.
INTERNAL METHODS
_set_error_message( $message )
Internal method to set the error message in the object before the parser returns.
DEBUG MODE
Sometimes it helps to see what the module would do instead of doing it. That's why I added the debug mode: If you do not set a printer object when calling the constructor, an XML::Printer::ESCPOS::Debug object is created. It catches all method calls and the parse
method returns the perl code that would have been executed if you had set the printer object.
This XML code
<escpos>
<utf8ImagedText
fontFamily = "DejaVu Sans"
fontStyle = "Bold"
fontSize = "76"
lineHeight = "115"
paperWidth = "832">This module</utf8ImagedText>
<lf />
<utf8ImagedText
fontFamily = "DejaVu Sans"
fontStyle = "Bold"
fontSize = "36"
lineHeight = "55"
paperWidth = "832"
>is great for writing templates</utf8ImagedText>
<qr>https://github.com/sonntagd/XML-Printer-ESCPOS</qr>
</escpos>
will create the following perl code:
$device->printer->utf8ImagedText(
'This module',
'fontFamily',
'DejaVu Sans',
'fontSize',
'76',
'fontStyle',
'Bold',
'lineHeight',
'115',
'paperWidth',
'832'
);
$device->printer->lf();
$device->printer->utf8ImagedText(
'is great for writing templates',
'fontFamily',
'DejaVu Sans',
'fontSize',
'36',
'fontStyle',
'Bold',
'lineHeight',
'55',
'paperWidth',
'832'
);
$device->printer->qr(
'https://github.com/sonntagd/XML-Printer-ESCPOS'
);
AUTHOR
Dominic Sonntag, <dominic at s5g.de>
BUGS
Please report any bugs or feature requests by opening an issue on Github: https://github.com/sonntagd/XML-Printer-ESCPOS/issues
LICENSE AND COPYRIGHT
Copyright 2017 Dominic Sonntag.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at: