Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
esc_pos_print_plus
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dio Maulana
esc_pos_print_plus
Commits
e34e6d51
Commit
e34e6d51
authored
Aug 31, 2019
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
printing images (beta)
parent
8a5e3cce
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
109 additions
and
3 deletions
+109
-3
CHANGELOG.md
CHANGELOG.md
+8
-0
README.md
README.md
+12
-1
example.dart
example/example.dart
+8
-1
logo.png
example/logo.png
+0
-0
commands.dart
lib/src/commands.dart
+3
-0
printer.dart
lib/src/printer.dart
+76
-0
pubspec.yaml
pubspec.yaml
+2
-1
No files found.
CHANGELOG.md
View file @
e34e6d51
## [1.2.0]
*
printing images (beta)
## [1.1.3]
*
printCodeTable bug fixed
*
updated test print example
## [1.1.2]
*
Better alignment
## [1.1.1]
*
Fixed columns alignment bug
## [1.1.0]
*
Added code page support
## [1.0.2]
*
Send raw command(s)
*
Turn 90° clockwise rotation mode on/off
...
...
README.md
View file @
e34e6d51
...
...
@@ -76,9 +76,20 @@ printer.printRow([
]);
```
Print image:
```
dart
import
'dart:io'
;
import
'package:image/image.dart'
;
const
String
filename
=
'./logo.png'
;
final
Image
image
=
decodeImage
(
File
(
filename
).
readAsBytesSync
());
printer
.
printImage
(
image
);
```
## TODO
*
~~Add raw print function~~
*
Print images
*
~~Print images~~
*
Print barcodes
*
Print QR codes
*
~~Turn 90° clockwise rotation mode on/off~~
...
...
example/example.dart
View file @
e34e6d51
import
'dart:io'
;
import
'package:esc_pos_printer/esc_pos_printer.dart'
;
import
'package:image/image.dart'
;
void
main
(
)
{
// To discover existing printers in your subnet, consider using
// ping_discover_network package (https://pub.dev/packages/ping_discover_network).
// Note that most of ESC/POS printers by default listen on port 9100.
Printer
.
connect
(
'192.168.0.123'
,
port:
9100
).
then
((
printer
)
{
printer
.
println
(
'Regular: aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ'
);
printer
.
println
(
'Regular: aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ'
);
printer
.
println
(
'Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ'
,
styles:
PosStyles
(
codeTable:
PosCodeTable
.
westEur
));
printer
.
println
(
'Special 2: blåbærgrød'
,
...
...
@@ -43,6 +46,10 @@ void main() {
width:
PosTextSize
.
size2
,
));
const
String
filename
=
'./logo.png'
;
final
Image
image
=
decodeImage
(
File
(
filename
).
readAsBytesSync
());
printer
.
printImage
(
image
);
printer
.
cut
();
printer
.
disconnect
();
});
...
...
example/logo.png
0 → 100644
View file @
e34e6d51
2.33 KB
lib/src/commands.dart
View file @
e34e6d51
...
...
@@ -44,3 +44,6 @@ const cPos = '$esc\$'; // Set absolute print position [nL] [nH]
// Print
const
cFeedN
=
'
${esc}
d'
;
// Print and feed n lines [N]
const
cReverseFeedN
=
'
${esc}
e'
;
// Print and reverse feed n lines [N]
// Bit Image
const
cImgPrint
=
'
${gs}
v0'
;
// Print raster bit image [obsolete command]
lib/src/printer.dart
View file @
e34e6d51
...
...
@@ -10,6 +10,7 @@ import 'dart:convert';
import
'dart:io'
;
import
'dart:typed_data'
;
import
'package:hex/hex.dart'
;
import
'package:image/image.dart'
;
import
'commands.dart'
;
import
'enums.dart'
;
import
'pos_column.dart'
;
...
...
@@ -281,4 +282,79 @@ class Printer {
_socket
.
write
(
cCutFull
);
}
}
/// Generate multiple bytes for a number: In lower and higher parts, or more parts as needed.
///
/// [value] Input number
/// [bytesNb] The number of bytes to output (1 - 4)
List
<
int
>
_intLowHigh
(
int
value
,
int
bytesNb
)
{
final
dynamic
maxInput
=
256
<<
(
bytesNb
*
8
)
-
1
;
if
(
bytesNb
<
1
||
bytesNb
>
4
)
{
throw
Exception
(
'Can only output 1-4 bytes'
);
}
if
(
value
<
0
||
value
>
maxInput
)
{
throw
Exception
(
'Number too large. Can only output up to
$maxInput
in
$bytesNb
bytes'
);
}
final
List
<
int
>
res
=
<
int
>[];
int
buf
=
value
;
for
(
int
i
=
0
;
i
<
bytesNb
;
++
i
)
{
res
.
add
(
buf
%
256
);
buf
=
buf
~/
256
;
}
return
res
;
}
List
<
int
>
_convert1bit
(
List
<
int
>
bytes
)
{
final
List
<
int
>
res
=
[];
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
+=
8
)
{
res
.
add
(
bytes
[
i
]);
}
return
res
;
}
/// Print image
///
/// [image] is an instanse of class from [Image library](https://pub.dev/packages/image)
void
printImage
(
Image
image
)
{
const
bool
highDensityHorizontal
=
true
;
const
bool
highDensityVertical
=
true
;
final
int
widthPx
=
image
.
width
;
final
int
heightPx
=
image
.
height
;
final
int
widthBytes
=
(
widthPx
+
7
)
~/
8
;
const
int
densityByte
=
(
highDensityVertical
?
0
:
1
)
+
(
highDensityHorizontal
?
0
:
2
);
final
List
<
int
>
header
=
List
.
from
(
cImgPrint
.
codeUnits
);
header
.
add
(
densityByte
);
header
.
addAll
(
_intLowHigh
(
widthBytes
,
2
));
header
.
addAll
(
_intLowHigh
(
heightPx
,
2
));
final
xL
=
header
[
4
];
final
xH
=
header
[
5
];
final
newWidth
=
(
xL
+
xH
*
256
)
*
8
;
final
Image
imgResized
=
copyResize
(
image
,
width:
newWidth
,
height:
image
.
height
);
final
Image
imgGreyscale
=
grayscale
(
imgResized
);
final
Image
imgInvert
=
invert
(
imgGreyscale
);
final
bytes
=
imgInvert
.
getBytes
(
format:
Format
.
luminance
);
final
res
=
_convert1bit
(
bytes
);
// print('img w * h (src): $widthPx * $heightPx');
// print('img w * h (new): ${imgResized.width} * ${imgResized.height}');
// print('source bytes: ${bytes.length}');
// print('= target bytes: ${(xL + xH * 256) * (header[6] + header[7] * 256)}');
// print('= to print bytes: ${res.length}');
// print(header);
sendRaw
(
List
.
from
(
header
)..
addAll
(
res
));
}
}
pubspec.yaml
View file @
e34e6d51
name
:
esc_pos_printer
description
:
The library allows to print receipts using a ESC/POS (usually thermal) network printer. It can be used in Flutter or Dart projects. In Flutter, both Android and iOS are supported.
version
:
1.
1.3
version
:
1.
2.0
author
:
Andrey Ushakov <flutter@tablemi.com>
homepage
:
https://github.com/andrey-ushakov/esc_pos_printer
...
...
@@ -11,6 +11,7 @@ dependencies:
flutter
:
sdk
:
flutter
hex
:
^0.1.2
image
:
^2.1.4
dev_dependencies
:
flutter_test
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment