Print Text, Images, and {ggplot2} or {grid} Objects to ESC/POS Compatible Network Devices
ESC/POS devices, such as receipt printers, have the ability to print their own form of raster bitmap graphics as well as text. Tools are provided to turn {ggplot2} or {grid} objects into such raster bitmaps and print them, along with text and regular images, to ESC/POS compatible devices.
The following functions are implemented:
ggpos: Print a ggplot (or other grid object) to an ESC/POS compatible network device with sensible defaultspng_to_raster: Convert any png file to ESC/POS raster formatpos_align: Text alignmentpos_bold: Bold textpos_color: Set colorpos_cr: Send a CR to the printerpos_cut: Issue a partial or full cut command to the printerpos_ff: Send a FF to the printerpos_font: Font choicepos_ht: Send a HT to the printerpos_inverted: Invert printingpos_lf: Send a LF to the printerpos_plaintext: Send plaintext to the printerpos_plot: Turn a ggplot (or other grid object) intto an ESC/POS bitmap for use in the DSLpos_print: Send collected print commands to the printerpos_size: Text sizepos_underline: Underlinepos_vt: Send a VT to the printerescpos: Create anescposobject for accumulating print commands
I’ve only tested this on a single, networked EPSON TM-T88V printer.
remotes::install_github("hrbrmstr/escpos", ref = "batman")library(escpos)
# current version
packageVersion("escpos")
## [1] '0.2.0'library(stringi)
library(hrbrthemes)
library(ggplot2)
ggplot() +
geom_point(
data = mtcars,
aes(wt, mpg),
color = "red"
) +
labs(
title = "A good title"
) +
theme_ipsum_es(grid="XY") -> gg
epson_ip = "HOSTNAME_OR_IP_OF_YOUR_PRINTER"
escpos(epson_ip) |>
pos_bold("on") %>%
pos_align("center") %>%
pos_size("2x") %>%
pos_underline("2dot") %>%
pos_plaintext("This Is A Title") %>%
pos_lf(2) |>
pos_underline("off") %>%
pos_size("normal") %>%
pos_align("left") %>%
pos_bold("off") %>%
pos_font("b") %>%
pos_plaintext(
stringi::stri_rand_lipsum(1)
) |>
pos_lf(2) |>
pos_font("a") %>%
pos_plaintext(
paste0(capture.output(
str(mtcars, width = 40, strict.width = "cut")
), collapse = "\n")
) |>
pos_lf(2L) |>
pos_plot(gg, color = TRUE) %>%
pos_lf(2L) |>
pos_font("c") %>%
pos_plaintext(
stringi::stri_rand_lipsum(1, start_lipsum = FALSE)
) |>
pos_lf(3) |>
pos_cut() %>%
pos_print()| Lang | # Files | (%) | LoC | (%) | Blank lines | (%) | # Lines | (%) |
|---|---|---|---|---|---|---|---|---|
| C++ | 6 | 0.16 | 7566 | 0.44 | 1233 | 0.35 | 1240 | 0.21 |
| C/C++ Header | 3 | 0.08 | 629 | 0.04 | 396 | 0.11 | 1374 | 0.23 |
| R | 7 | 0.18 | 250 | 0.01 | 80 | 0.02 | 315 | 0.05 |
| Rmd | 1 | 0.03 | 54 | 0.00 | 22 | 0.01 | 34 | 0.01 |
| YAML | 2 | 0.05 | 35 | 0.00 | 10 | 0.00 | 2 | 0.00 |
| SUM | 19 | 0.50 | 8534 | 0.50 | 1741 | 0.50 | 2965 | 0.50 |
clock Package Metrics for escpos
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
