Skip to content

R 📦 for printing text, images, and {ggplot2} or {grid} objects to ESC/POS compatible network devices

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

hrbrmstr/escpos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Signed by Signed commit % R-CMD-check Linux build Status
Minimal R Version License

escpos

Print Text, Images, and {ggplot2} or {grid} Objects to ESC/POS Compatible Network Devices

Description

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.

What’s Inside The Tin

The following functions are implemented:

  • ggpos: Print a ggplot (or other grid object) to an ESC/POS compatible network device with sensible defaults
  • png_to_raster: Convert any png file to ESC/POS raster format
  • pos_align: Text alignment
  • pos_bold: Bold text
  • pos_color: Set color
  • pos_cr: Send a CR to the printer
  • pos_cut: Issue a partial or full cut command to the printer
  • pos_ff: Send a FF to the printer
  • pos_font: Font choice
  • pos_ht: Send a HT to the printer
  • pos_inverted: Invert printing
  • pos_lf: Send a LF to the printer
  • pos_plaintext: Send plaintext to the printer
  • pos_plot: Turn a ggplot (or other grid object) intto an ESC/POS bitmap for use in the DSL
  • pos_print: Send collected print commands to the printer
  • pos_size: Text size
  • pos_underline: Underline
  • pos_vt: Send a VT to the printer
  • escpos: Create an escpos object for accumulating print commands

NOTE

I’ve only tested this on a single, networked EPSON TM-T88V printer.

Installation

remotes::install_github("hrbrmstr/escpos", ref = "batman")

Usage

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()

escpos Metrics

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

Code of Conduct

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.

About

R 📦 for printing text, images, and {ggplot2} or {grid} objects to ESC/POS compatible network devices

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages