XML::Printer::ESCPOS - An XML parser for generating ESCPOS output.
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.
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();
Constructs a new XML::Printer::ESCPOS object. You must provide a printer object you get by Printer::ESCPOS-new(...)->printer>.
Printer::ESCPOS-
If you do not set a printer, the module works in debug mode (see below).
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.
$xml
errormessage
Returns the last error message.
Internal method to set the error message in the object before the parser returns.
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.
parse
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' );
Dominic Sonntag, <dominic at s5g.de>
<dominic at s5g.de>
Please report any bugs or feature requests by opening an issue on Github: https://github.com/sonntagd/XML-Printer-ESCPOS/issues
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:
http://www.perlfoundation.org/artistic_license_2_0
To install XML::Printer::ESCPOS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::Printer::ESCPOS
CPAN shell
perl -MCPAN -e shell install XML::Printer::ESCPOS
For more information on module installation, please visit the detailed CPAN module installation guide.