Skip to content

Commit

Permalink
Update 2024-01-23-thermal.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ibbsbbr authored Jan 29, 2024
1 parent d1ebe20 commit 624d642
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions _posts/2024-01-23-thermal.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,30 @@ title: 'Script to print from clipboard to a thermal printer'

---

# text printing

```
#!/bin/bash
# Script to print formatted text from clipboard to a thermal printer
# Check for the presence of xclip
if ! command -v xclip &>/dev/null; then
echo "xclip could not be found."
exit 1
fi
# Get clipboard content using xclip
clipboard_content="$(xclip -o -selection clipboard)"
# Escape % to prevent printf interpretation
escaped_content=$(sed 's/%/%%/g' <<<"$clipboard_content")
# Convert the encoding while suppressing the specific 'iconv' error
converted_text=$(iconv -f UTF-8 -t CP850//TRANSLIT//IGNORE <<<"$escaped_content" 2>/dev/null)
# Print the formatted text to the thermal printer
if ! printf '\x1B\x40\x1B\x21\x08\x1B\x61\x01%s\x0A\x0A\x0A\x1B\x69' "$converted_text" | lp -d thermal -o raw; then
echo "Failed to print. Please check the printer and its configuration."
exit 1
Expand All @@ -39,6 +50,8 @@ fi

```
#!/bin/bash
if ! command -v xclip &>/dev/null; then
echo "xclip could not be found."
exit 1
Expand Down

0 comments on commit 624d642

Please sign in to comment.