Aktivieren von Fettdruck und Farbe mit dem parallelen LPT-Drucker

1371
Blue Ice

Ich weiß, wie ich Text auf meinem HP Deskjet 420-Drucker unter Lubuntu mit Bash wiedergeben kann:

echo -e "line of text" > /dev/lp0 

Gibt es eine Möglichkeit, fett gedruckten oder farbigen Text zu drucken? Sollte ich eine Art Escape-Befehl an den Drucker senden?

Vielen Dank.

2
Die Konvertierung von ANSI-geschütztem Text in pdf (derzeit von aha + wkhtmltopdf durchgeführt) scheint etwas 'enscript' oder 'paps' zu sein. Versuchen Sie, einen 'Wunschlisten'-Fehler mit einem von ihnen zu senden. vor 9 Jahren 0

1 Antwort auf die Frage

1
terdon

The way to echo bold or colored text in a terminal is to use ANSI escape codes. For example, try this:

$ echo -e '\033[01;1mthis text will be bold\033[00;0m this will not'
this text will be bold this will not

The escape sequence \033[01;1m causes the following text to be bold and \033[00;0m turns all attributes off, so it goes back to normal.

See here for a nice list of the various escape sequences.

Unfortunately, lp does not know how to deal with this. It only knows how to print postscript files. We therefore need a way of turning the ANSI escape characters into formatted postscript. I was intrigued by this question so I posted one of my own on U&L asking about ways of interpreting the ANSI escapes as postscript commands. The following is from the answer I got there, please go upvote it!

You will need the following tools:

  • aha : Ansi HTML Adapter, this program can translate ANSI escape codes to HTML.

    DESCRIPTION aha takes SGR-colored Input and prints W3C conform HTML-Code. aha reads the Input from a file or stdin and writes HTML-Code to stdout. 

    Install:

    sudo apt-get install aha 
  • wkhtmltopdf : An HTML to PDF converter.

    Description Converts one or more HTML pages into a PDF document, not using wkhtmltopdf patched qt. 

    Install:

    sudo apt-get install wkhtmltopdf 

Now, put them all together. I will use this command whose output is shown in the image below:

echo -e '\033[01;1mbold\033[00;0m,not bold, and \033[32;1mgreen' 

enter image description here

So, let's print it:

echo -e '\033[01;1mbold\033[00;0m,not bold, and \033[32;1mgreen' |  aha | wkhtmltopdf - - | lpr 

And that's it, that will print a nice, formatted bold and colored line of text.

Ich fühle mich sehr alt, dass jemand davon nicht sofort erfahren würde. :) Alan B vor 11 Jahren 0
Ich denke, es hat mehr mit deiner allgemeinen Geekiness als mit deinem Alter zu tun :) terdon vor 11 Jahren 1
@terdon Ich bin mir sicher, dass es eine Art Escape-Code ist. Ich habe ein schnelles Bash-Skript erstellt, um zu sehen, welche Art von Zeichen es drucken kann, und es ist eine ungerade Menge von 256 Zeichen, die nicht Bash sind. Verwendet \ x und Hex (z. B. \ x9e) und unterscheidet sich von den Bunt-Zeichen von Lubuntu für dieselben Werte. Blue Ice vor 11 Jahren 0
Beispielsweise ist \ x1 ein Smiley und \ xc ein Seitenumbruch. In Bash sieht man nicht so viel :) Blue Ice vor 11 Jahren 0
@BlueIce Entschuldigung, aber ich habe absolut keine Ahnung, wovon Sie sprechen :). Aber warten Sie, ich habe herausgefunden, wie das geht, ich werde in Kürze eine aktualisierte Antwort veröffentlichen. terdon vor 11 Jahren 0
@BlueIce OK, ich verstehe was du meinst, es ist eigentlich dasselbe, \ 033 und `\ x` sind beide` ESC`. Schauen Sie sich die aktualisierte Antwort an und sehen Sie sich die sehr schöne Antwort auf U & L an, die sie mir gegeben hat :). terdon vor 11 Jahren 0
@terdon Alles klar. Ich werde es testen. Blue Ice vor 11 Jahren 0