Skip to content

Instantly share code, notes, and snippets.

@brandoncordell
Created September 19, 2017 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandoncordell/012441ce82e0902b13cab1786abb6dc3 to your computer and use it in GitHub Desktop.
Save brandoncordell/012441ce82e0902b13cab1786abb6dc3 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Starprinter Test</title>
</head>
<body>
<h1>Welcome page</h1>
<script type="text/javascript">
/*
//Example
var command = new PrinterCommand('myprinter');
command.feed(4);
command.text('Hello, World!');
command.feed(2);
command.text('Goodbye!');
command.feed(4);
command.cut();
command.print();
*/
/* eslint-disable max-len */
function PrinterCommand(alias) {
this.alias = alias;
this.command = [];
this.style = new PrinterCommand.StarPrinterTextStyle();
this.blockTime = 10000;
this.print = function print() {
return StarPrinter.send_commands(this.alias, this.blockTime, JSON.stringify(this.command));
};
this.setStyle = function setStyle(style) {
this.style = style;
};
this.text = function text(textToPrint) {
const style = this.style;
this.command = this.command.concat(JSON.parse(StarPrinter.getTextCommand(textToPrint, style.slashedZero, style.underline, style.invertColor, style.emphasized, style.upperline, style.upsideDown, style.heightExpansion, style.widthExpansion, style.leftMargin, style.alignment)));
};
this.PDF417 = function PDF417(text) {
this.command = this.command.concat(JSON.parse(StarPrinter.getPdf147Command(text, true, 5, 10, 0, 5, 1)));
};
this.QR = function QR(text) {
this.command = this.command.concat(JSON.parse(StarPrinter.getQRCommand(text, 0, 2, 5)));
};
this.image = function image(filepath, maxWidth) {
this.command = this.command.concat(JSON.parse(StarPrinter.getImageFileCommand(filepath, maxWidth, true)));
};
this.base64Image = function base64Image(data, maxWidth, onFinished) {
this.command = this.command.concat(JSON.parse(StarPrinter.getBase64ImageCommand(data, maxWidth, true)));
onFinished();
};
this.code39 = function code39(data, option, height, width) {
this.command = this.command.concat(JSON.parse(StarPrinter.getCode39Command(data, option, height, width)));
};
this.code93 = function code93(data, option, height, width) {
this.command = this.command.concat(JSON.parse(StarPrinter.getCode93Command(data, option, height, width)));
};
this.codeITF = function code39(data, option, height, width) {
this.command = this.command.concat(JSON.parse(StarPrinter.getCodeITFCommand(data, option, height, width)));
};
this.code128 = function code128(data, option, height, width) {
this.command = this.command.concat(JSON.parse(StarPrinter.getCode128Command(data, option, height, width)));
};
this.feed = function feed(lines) {
this.command = this.command.concat(JSON.parse(StarPrinter.getLineFeedCommand(lines)));
};
this.cut = function cut(text) {
this.command = this.command.concat(JSON.parse(StarPrinter.getCutCommand()));
};
}
PrinterCommand.StarPrinterTextStyle = function StarPrinterTextStyle() {
this.slashedZero = false;
this.underline = false;
this.invertColor = false;
this.emphasized = false;
this.upperline = false;
this.upsideDown = false;
this.heightExpansion = 0;
this.widthExpansion = 0;
this.leftMargin = 0;
this.alignment = 0;
};
var command = new PrinterCommand('star'); // alias inside of Kioware is: star
command.feed(4);
command.text('Hello, World!');
command.feed(2);
command.text('Goodbye!');
command.feed(4);
command.cut();
command.print();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment