Skip to content

Repository files navigation

GitHub release (latest SemVer)version on pypipython versions on pypitests statuspython docstring coveragepython test coveragelicenseDonate

EscaPy

EscaPy is a thoroughly tested tool that reliably and almost exhaustively interprets the ESC/P and ESC/P2 command sets defined by Epson (Wikipedia - Epson ESC/P), then converts the data formerly intended for printers into a modern PDF file.

Table of Contents

Open Contents

ℹ️ About the Project

TL;DR: Your DOS system or emulator will be able to produce searchable PDF files. This tool is compatible with files produced by the Libre Printer interface discussed below.

📖 Foreword

Nowadays, older equipment may still be in use in sectors such as medical or industrial (machine tools). While the software of the old days were often designed to use dot-matrix printers exclusively, these printers can break down or can no longer be used due to a lack of consumables available on the market.

As a result, the entire system has to be replaced without justification.

EscaPy generates PDF files from the raw data sent to the printer. Files can therefore be stored permanently, printed on new hardware, indexed by an archiving system (text remains accessible) or simply consulted at any time.

Note that data destined for the printer must be captured in some way. The Libre Printer project accomplishes exactly this task by providing a software and hardware interface pretending to be a printer compatible with older hardware.

🏦 Donations

EscaPy is a project that took ~2 months of full-time work and 12k+ lines including documentation & tests, for its first version. If it has been useful to you in any way and you would like to contribute to its development, please follow the link below, with all thanks :

Donate

1EB6dc6YULzHR4TMqLi5fomZ6wmdP3N5cW

⭐ Features

  • Advanced ESC/P ESC/P2 command set support

    Nearly all commands are supported (text, graphics and barcodes).

    ! See details & coverage of the command set !

    *: Not recommended command.
    ‡: Extended command (added on modern printers)
    ✅: Implemented.
    ❗: Not fully implemented.
    ⬜: Not implemented.
    🚫: Will not be implemented.

    Setting the page format
    ESC ( CSet page length in defined unit
    ESC ( cSet page format
    ESC CSet page length in lines
    ESC C NULSet page length in inches
    ESC NSet bottom margin
    ESC OCancel bottom margin
    ESC QSet right margin
    ESC lSet left margin
    ESC ( SSet paper dimensions‡
    Moving the print position
    CRCarriage return
    LFLine feed
    FFForm feed
    ESC $Set absolute horizontal print position
    ESC ( $Set absolute horizontal print position‡
    ESC \Set relative horizontal print position
    ESC ( /Set relative horizontal print position‡
    ESC ( VSet absolute vertical print position
    ESC ( vSet relative vertical print position
    ESC JAdvance print position vertically
    HTTab horizontally
    VTTab vertically
    ESC fHorizontal/vertical skip*
    BSBackspace*
    Setting the units
    ESC ( USet unit
    ESC 0Select 1/8-inch line spacing
    ESC 2Select 1/6-inch line spacing
    ESC 3Set n/180-inch line spacing
    ESC 3Set n/216-inch line spacing
    ESC +Set n/360-inch line spacing
    ESC ASet n/60-inch line spacing*
    ESC ASet n/72-inch line spacing*
    ESC 1Select 7/72-inch line spacing*
    ESC DSet horizontal tabs
    ESC BSet vertical tabs
    ESC bSet vertical tabs in VFU channels*
    ESC /Select vertical tab channel*
    ESC eSet fixed tab increment*
    ESC aSelect justification*
    Selecting characters
    ESC ( tAssign character table
    ESC tSelect character table
    ESC RSelect an international character set
    ESC &Define user-defined characters
    ESC :Copy ROM to RAM
    ESC %Select user-defined set
    ESC xSelect LQ or draft
    ESC xSelect NLQ or draft
    ESC kSelect typeface
    ESC XSelect font by pitch and point
    ESC cSet horizontal motion index (HMI)
    ESC PSelect 10.5-point, 10-cpi
    ESC PSelect 10-cpi
    ESC MSelect 10.5-point, 12-cpi
    ESC MSelect 12-cpi
    ESC gSelect 10.5-point, 15-cpi
    ESC gSelect 15-cpi
    ESC pTurn proportional mode on/off
    ESC SPSet intercharacter space
    ESC ESelect bold font
    ESC FCancel bold font
    ESC 4Select italic font
    ESC 5Cancel italic font
    ESC !Master select
    ESC GSelect double-strike printing
    ESC HCancel double-strike printing
    ESC -Turn underline on/off
    ESC ( -Select line/score
    ESC SSelect superscript/subscript printing
    ESC TCancel superscript/subscript printing
    ESC qSelect character style
    SISelect condensed printing
    ESC SISelect condensed printing*
    DC2Cancel condensed printing
    SOSelect double-width printing (one line)
    ESC SOSelect double-width printing (one line)*
    DC4Cancel double-width printing (one line)
    ESC WTurn double-width printing on/off
    ESC wTurn double-height printing on/off
    Control-code character printing
    ESC ( ^Print data as characters
    ESC 6Enable printing of upper control codes
    ESC 7Enable upper control codes
    ESC IEnable printing of control codes
    ESC mSelect printing of upper control codes*
    Mechanical control
    ESC EMControl paper loading/ejecting
    ESC UTurn unidirectional mode on/off🚫
    ESC <Unidirectional mode (one line)*🚫
    BELBeeper*🚫
    ESC 8Disable paper-out detector*🚫
    ESC 9Enable paper-out detector*🚫
    ESC sSelect low-speed mode*🚫
    Printing color and graphics
    ESC ( GSelect graphics mode
    ESC . 0 / ESC . 1Print raster graphics
    ESC . 2Enter TIFF RLE compressed mode
    ESC . 3Enter TIFF Delta Row compressed mode‡
    ESC *Select bit image
    ESC ?Reassign bit-image mode*
    ESC KSelect 60-dpi graphics*
    ESC LSelect 120-dpi graphics*
    ESC YSelect 120-dpi, double-speed graphics*
    ESC ZSelect 240-dpi graphics*
    ESC ^Select 60/120-dpi, 9-pin graphics
    ESC rSelect printing color
    ESC ( rSelect printing color‡
    ESC ( DSet raster resolution‡
    ESC iTransfer raster image‡
    Printing method control
    ESC ( iSelect MicroWeave print mode
    ESC ( eSelect Ink Drop Size‡
    ESC ( KSet monochrome/color mode‡
    ESC ACKFlush buffers after MicroWeave print mode‡🚫
    ESC ( mSet print method‡🚫
    Printing bar codes
    ESC ( BBar code setup and print
    Data and memory control
    ESC SOH @EJL 1284.4\n@EJL \nExit packet mode
    ESC SOH @EJL 1284.4\n@EJL\n@EJL\nEnter D4 mode
    ESC @Initialize printer
    CANCancel line*
    DELDelete last character in buffer*
    DC1Select printer*🚫
    DC3Deselect printer*🚫
    ESC #Cancel MSB control*
    ESC =Set MSB to 0*
    ESC >Set MSB to 1*
    Deleted commands
    ESC jReverse paper feed*🚫
    ESC iSelect immediate print mode*🚫
    Binary mode commands for ESC . 2
    & ESC . 3 raster graphics modes
    <XFER>Transfer raster graphics data
    <CLR>Clear seed row (Delta Row compression)‡
    <MOVX>Set relative horizontal position
    <MOVY>Set relative vertical position
    <COLR>Select printing color
    <CR>Carriage return to left-most print position
    <EXIT>Exit TIFF compressed mode
    <MOVXBYTE>Set unit to 8 dots
    <MOVXDOT>Set unit to 1 dot
    Remote commands
    (all commands are supported, but
    only a few useful ones are
    implemented.)
    ESC ( RSet remote mode‡
    ESC NUL NUL NULExit remote mode‡
    RSReset printer‡
    FPSet relative left margin‡
    JHSet job name‡
    JSStart job‡
  • Advanced font support

    Specify in advance the fonts you wish to use. 14 different fonts can be specified, each in 2 versions (fixed and proportional fonts), for a total of 28 fonts.

    Use system-installed or custom fonts.

    Text enhancements (strikethrough, underline, highlight, etc.) are supported.


    Fonts examples & character style implementations.
  • Several rendering modes for graphic commands

    Points can be rendered as dots or rectangles. In all cases, the file is vectorized (infinitely scalable).


    Graphic element magnifications. Two ways of rendering.

    Delta Row compression with 720p rendering.
    • NB: Rendering as an image is not yet available, but such a result can be obtained with GhostScript for this task (see examples).

    • Note regarding color rendering: When two CMYK colored objects overlap in printing, then either the object 'on top' will knock out the color of the one underneath it, or the colors of the two objects will mix in the overlapped area. This behaviour can be set using the property overPrint of your PDF viewer. This is mandatory for a good rendering of the PDF files built by Escapy.


    On Okular, since June 2023, the option is under the “Configure Rendering Engines” / “Enable Overprint Preview”
  • Searchable text

    Text remains as text, not as images. This makes content search and indexing possible.

  • Wide range of encodings available

    A major effort has been made to ensure that the essential encodings of this era and more, are also supported by EscaPy. It's easy to add to this list. Contributions are welcome.

    Characters that can be printed in the place of the intervals dedicated to control characters, and international characters (National Replacement Character Set) are also injected into the encoding tables.


    Support for many common encodings.

    NB: It is still necessary to ensure that the fonts used support the selected character sets.

    See details
    • PC437 (US)
    • PC437 Greek
    • PC932 (Japanese)
    • PC850 (Multilingual)
    • PC851 (Greek)
    • PC853 (Turkish)
    • PC855 (Cyrillic)
    • PC860 (Portugal)
    • PC863 (Canada-French)
    • PC865 (Norway)
    • PC852 (East Europe)
    • PC857 (Turkish)
    • PC862 (Hebrew)
    • PC864 (Arabic)
    • PC AR864
    • PC866 (Russian)
    • (Bulgarian ASCII****)
    • PC866 LAT. (Latvian)
    • PC869 (Greek)
    • USSR GOST (Russian)
    • ECMA-94-1
    • KU42 (K.U. Thai)
    • TIS11 (TS 988 Thai)
    • TIS18 (GENERAL Thai)
    • TIS17 (SIC STD. Thai)
    • TIS13 (IBM STD. Thai)
    • TIS16 (SIC OLD Thai)
    • PC861 (Iceland)
    • BRASCII
    • Abicomp
    • MAZOWIA (Poland)
    • Code MJK (CSFR)
    • ISO8859-7 (Latin/Greek)
    • ISO8859-1 (Latin 1)
    • TSM/WIN (Thai system manager)
    • ISO Latin 1T (Turkish)
    • Bulgaria
    • Hebrew 7
    • Hebrew 8
    • Roman 8
    • PC774 (Lithuania)
    • Estonia (Estonia)
    • ISCII
    • PC-ISCII
    • PC APTEC
    • PC708
    • PC720
    • OCR-B
    • ISO Latin 1
    • ISO 8859-2 (ISO Latin 2)
    • ISO Latin 7 (Greek)
  • Page formats

    47 portrait formats and their landscape equivalents are predefined. Custom sizes are also available.

  • User-defined characters support (ESC/P2 only)

    A user can send customized bitmap characters to the printer. A mapping file will be generated to map the received characters to modern unicode codes (see examples).

  • Enhanced reliability thanks to testing (~100%)

    EscaPy is an implementation of a standard made up of over 600 pages covered by almost 300 tests.

    A coverage rate close to 100% eliminates most of the erratic behavior that a non-rigorously tested application can produce.

    However, a coverage rate of 100% does not guarantee that the program rigorously follows the standard, but that its behavior is most often in line with what the developer expected when he designed it.

  • Facilitated development

    The code is fully documented to facilitate maintenance and enhancements.

⚙ Setup

Installation

All operating systems should be supported, although this project is mainly developed for a GNU-Linux system as an everyday computer.

Simple installation from PyPI (beware, the package name is not the project name!):

$ pip install pyscape

Installation from sources :

$ pip install .

Install the project in editable mode for developpers :

$ make install
# Or
$ pip install -e .[dev]

Installation on Debian :

apt install ./escapy_1.0.0-2_all.deb

Usage

$ escapy -h
usage: [-h] [--pins [PINS]] [--single_sheets | --no-single_sheets] [-o [OUTPUT]]
[-c [CONFIG]] [-db [USERDEF_DB_FILEPATH]] [-v]
esc_prn
positional arguments:
esc_prn ESC raw printer file. - to read from stdin.
options:
-h, --help show this help message and exit
--pins [PINS] number of needles of the print head (9, 24, 48). Leave it unsetfor ESCP2 modern printers. (default: unset)
--single_sheets, --no-single_sheets
single-sheets or continuous paper. (default: single-sheets)
-o [OUTPUT], --output [OUTPUT]
PDF output file. - to write on stdout. (default: output.pdf)
-c [CONFIG], --config [CONFIG]
configuration file to use. (default: ./escapy.conf,
~/.local/share/escapy/escapy.conf)
-db [USERDEF_DB_FILEPATH], --userdef_db_filepath [USERDEF_DB_FILEPATH]
mappings between user-defined chararacter codes and unicode.
(default: ./user_defined_mapping.json)
-v, --version show program's version number and exit

NB : The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

Examples

Standard input/output streams are active, so it is possible to chain tools :

$ cat my_file.prn | escapy - -o - > my_pdf.pdf

For example, to convert the generated PDF into a TIFF image with GhostScript :

$ cat my_file.prn | escapy - -o - | \
gs -dBATCH -dNOPAUSE -dSAFER \
-dNoSeparationFiles -dSimulateOverprint=true -sDEVICE=tiffsep -r720 \
-sOutputFile=out-%d.tiff -

📰 Configuration file

The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

By default, the escapy.conf file is searched for in the current folder. If it doesn't exist, it is searched for in the standard software configuration folder on your system (see below). This folder is created if it doesn't already exist.

On GNU/Linux systems: ~/.local/share/escapy/, /etc/escapy/escapy.conf

On Windows systems: C:\\Users\\<YOUR_USERNAME>\\AppData\\Local\\escapy

On MacOS systems: /Users/<YOUR_USERNAME>/Library/Application Support/escapy

The default file is in the repository folder: data.

📰 Printer profiles

Profile example:

[colors]
0 = black
[color:black]
display = Black
offset = 120
rgb = #000000
cmyk = 0,0,0,100
[color:black:mono]
offset = 0

Profiles are files stored by default in a profiles folder next to the default configuration file installed on the system (see above).

They contain a section listing the colors used by the printer, as well as a section defining each of these colors as follows.

Expected keys in each color section:

  • rgb: RGB color code (starting with a #);
  • cmyk: CMYK channels (4 coma separated values).

Optional keys:

  • display: Human readable name;
  • offset: Nozzle position adjustement offset (in 1/180th of an inch).

Regarding nozzle offsets:
Most Epson print heads align all color nozzles on the same horizontal line. However, some models use one color as a reference, with the other color nozzles physically offset from it.

We need to compensate for the data generated by the driver in order to determine the correct position of the received colored data.

Depending on whether monochrome or color mode is selected, the range of nozzles may vary. That's why each color can be found in a dedicated monochrome version.

🔤 Fonts

For reasons of licensing and personal preference, EscaPy does not embed fonts (except for a minimal version of Courier and Helvetica).

List of fonts that can be embedded in Epson printers
  • Roman
  • Sans serif
  • Courier
  • Prestige
  • Script
  • OCR-B
  • OCR-A
  • Orator
  • Orator-S
  • Script C

Free fonts a proprietary equivalents :

ProprietaryFree ->
Courier NewLiberation MonoNoto Sans MonoFreeMonoFira Mono, Fira CodeRoboto Mono
Times New RomanLiberation SerifNoto SerifFreeSerifFiraGORoboto Serif
ArialLiberation SansNoto SansFreeSansFira SansRoboto
OCR-A / OCR-B fontsSquare
stroke ends OCR-A & OCR-B
Rounded ends & extended character coverage OCR-B

See also Recursive free font :

Free bitmap-style fonts :

Non-free fonts or fonts with restrictive licenses, often with a very limited character set, but close to the embedded fonts on Epson printers :


Noto, FreeFont and Fira fonts are normally installed on most systems, but can also be installed manually with the following command (on Debian systems and derivatives):

$ apt install fonts-noto fonts-freefont-ttf fonts-firacode

The same goes for Liberation fonts:

$ apt install fonts-liberation

Windows proprietary fonts can be installed with the following command:

$ apt install ttf-mscorefonts-installer

More generally, think of the fnt tool as a package manager for managing and installing fonts.

🅰️ User-defined characters

A JSON file is created and updated when custom characters are found. The user must specify the desired character in the unicode character set. The changes will be applied to the PDF by restarting the software.

Example:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "\ufffd"
}
}

Here, a character is defined under the unique key 83e1a70_1; the character with code 1 in the table is momentarily associated with the undefined character \ufffd (UNDEFINED).

A modification to match this code with the character could be as follows:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "♫"
}
}

By default, the JSON file (user_defined_mapping.json) is created in the current folder, but this can be changed in the configuration file. A folder containing the image of the bitmap character received can also be created by enabling the option images_path in the section [UserDefinedCharacters] of the configuration file.

🈳 Unsupported encodings (Chinese, Japanese, etc.)

The ESC/P and ESC/P2 standards do not seem to support Chinese or Japanese languages (encodings were apparently not provided for). However, some language evolutions (ESC/POS, ESC/P-K, ESC/P J84) and printers do support this. While in theory these languages can be implemented, their documentation remains hard to find and is beyond the scope of the current project. See Wikipedia - ESC variants.

The easiest way to achieve this is to use the printer in graphics mode (raster or bitimage) instead of text mode.

🏆 Acknowledgements

  • The management of modern fonts and their display on our screens would not have been possible without the work of French engineer Pierre Bézier (1910-1999), who also, through his work at Renault, revolutionized computer-aided design (CAD).

  • The Epson-Seiko teams of the 90's deserve our thanks for producing complete documentation of the language interpreted by their printers.

Absence of acknowledgements

Since the 2010s, Epson-Seiko (like so many other brands) tends to no longer publish language evolutions or advanced technical specifications for their machines. The brand tends to consider that this is now an industrial secret and none of your business.

In an ethical world, we wouldn't have to decipher these proprietary protocols. If you too feel that this is not appropriate, then you should consider manufacturers who respect your right to repair/modify what you own.

👏🏻 Contributions

This project is open for any contribution! Any bug report can be posted by opening an issue.

📖 License

EscaPy is distributed under two licenses: one for community use and the other for commercial use.

Community = Free and Open Source

EscaPy is released under the AGPL (Affero General Public License).

Commercial

The aim is to limit the uses integrated into proprietary devices whose vendors do not participate in the project in an equitable way, and who are guilty of any violation of the EscaPy license or of the free software used by EscaPy itself.

If you are interested in this license, please contact us.

Top ⬆️


Built with ❤️ with Document My Project

About

An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs.

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
GitHub - ysard/escapy: An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs. · GitHub
Skip to content

Repository files navigation

GitHub release (latest SemVer)version on pypipython versions on pypitests statuspython docstring coveragepython test coveragelicenseDonate

EscaPy

EscaPy is a thoroughly tested tool that reliably and almost exhaustively interprets the ESC/P and ESC/P2 command sets defined by Epson (Wikipedia - Epson ESC/P), then converts the data formerly intended for printers into a modern PDF file.

Table of Contents

Open Contents

ℹ️ About the Project

TL;DR: Your DOS system or emulator will be able to produce searchable PDF files. This tool is compatible with files produced by the Libre Printer interface discussed below.

📖 Foreword

Nowadays, older equipment may still be in use in sectors such as medical or industrial (machine tools). While the software of the old days were often designed to use dot-matrix printers exclusively, these printers can break down or can no longer be used due to a lack of consumables available on the market.

As a result, the entire system has to be replaced without justification.

EscaPy generates PDF files from the raw data sent to the printer. Files can therefore be stored permanently, printed on new hardware, indexed by an archiving system (text remains accessible) or simply consulted at any time.

Note that data destined for the printer must be captured in some way. The Libre Printer project accomplishes exactly this task by providing a software and hardware interface pretending to be a printer compatible with older hardware.

🏦 Donations

EscaPy is a project that took ~2 months of full-time work and 12k+ lines including documentation & tests, for its first version. If it has been useful to you in any way and you would like to contribute to its development, please follow the link below, with all thanks :

Donate

1EB6dc6YULzHR4TMqLi5fomZ6wmdP3N5cW

⭐ Features

  • Advanced ESC/P ESC/P2 command set support

    Nearly all commands are supported (text, graphics and barcodes).

    ! See details & coverage of the command set !

    *: Not recommended command.
    ‡: Extended command (added on modern printers)
    ✅: Implemented.
    ❗: Not fully implemented.
    ⬜: Not implemented.
    🚫: Will not be implemented.

    Setting the page format
    ESC ( CSet page length in defined unit
    ESC ( cSet page format
    ESC CSet page length in lines
    ESC C NULSet page length in inches
    ESC NSet bottom margin
    ESC OCancel bottom margin
    ESC QSet right margin
    ESC lSet left margin
    ESC ( SSet paper dimensions‡
    Moving the print position
    CRCarriage return
    LFLine feed
    FFForm feed
    ESC $Set absolute horizontal print position
    ESC ( $Set absolute horizontal print position‡
    ESC \Set relative horizontal print position
    ESC ( /Set relative horizontal print position‡
    ESC ( VSet absolute vertical print position
    ESC ( vSet relative vertical print position
    ESC JAdvance print position vertically
    HTTab horizontally
    VTTab vertically
    ESC fHorizontal/vertical skip*
    BSBackspace*
    Setting the units
    ESC ( USet unit
    ESC 0Select 1/8-inch line spacing
    ESC 2Select 1/6-inch line spacing
    ESC 3Set n/180-inch line spacing
    ESC 3Set n/216-inch line spacing
    ESC +Set n/360-inch line spacing
    ESC ASet n/60-inch line spacing*
    ESC ASet n/72-inch line spacing*
    ESC 1Select 7/72-inch line spacing*
    ESC DSet horizontal tabs
    ESC BSet vertical tabs
    ESC bSet vertical tabs in VFU channels*
    ESC /Select vertical tab channel*
    ESC eSet fixed tab increment*
    ESC aSelect justification*
    Selecting characters
    ESC ( tAssign character table
    ESC tSelect character table
    ESC RSelect an international character set
    ESC &Define user-defined characters
    ESC :Copy ROM to RAM
    ESC %Select user-defined set
    ESC xSelect LQ or draft
    ESC xSelect NLQ or draft
    ESC kSelect typeface
    ESC XSelect font by pitch and point
    ESC cSet horizontal motion index (HMI)
    ESC PSelect 10.5-point, 10-cpi
    ESC PSelect 10-cpi
    ESC MSelect 10.5-point, 12-cpi
    ESC MSelect 12-cpi
    ESC gSelect 10.5-point, 15-cpi
    ESC gSelect 15-cpi
    ESC pTurn proportional mode on/off
    ESC SPSet intercharacter space
    ESC ESelect bold font
    ESC FCancel bold font
    ESC 4Select italic font
    ESC 5Cancel italic font
    ESC !Master select
    ESC GSelect double-strike printing
    ESC HCancel double-strike printing
    ESC -Turn underline on/off
    ESC ( -Select line/score
    ESC SSelect superscript/subscript printing
    ESC TCancel superscript/subscript printing
    ESC qSelect character style
    SISelect condensed printing
    ESC SISelect condensed printing*
    DC2Cancel condensed printing
    SOSelect double-width printing (one line)
    ESC SOSelect double-width printing (one line)*
    DC4Cancel double-width printing (one line)
    ESC WTurn double-width printing on/off
    ESC wTurn double-height printing on/off
    Control-code character printing
    ESC ( ^Print data as characters
    ESC 6Enable printing of upper control codes
    ESC 7Enable upper control codes
    ESC IEnable printing of control codes
    ESC mSelect printing of upper control codes*
    Mechanical control
    ESC EMControl paper loading/ejecting
    ESC UTurn unidirectional mode on/off🚫
    ESC <Unidirectional mode (one line)*🚫
    BELBeeper*🚫
    ESC 8Disable paper-out detector*🚫
    ESC 9Enable paper-out detector*🚫
    ESC sSelect low-speed mode*🚫
    Printing color and graphics
    ESC ( GSelect graphics mode
    ESC . 0 / ESC . 1Print raster graphics
    ESC . 2Enter TIFF RLE compressed mode
    ESC . 3Enter TIFF Delta Row compressed mode‡
    ESC *Select bit image
    ESC ?Reassign bit-image mode*
    ESC KSelect 60-dpi graphics*
    ESC LSelect 120-dpi graphics*
    ESC YSelect 120-dpi, double-speed graphics*
    ESC ZSelect 240-dpi graphics*
    ESC ^Select 60/120-dpi, 9-pin graphics
    ESC rSelect printing color
    ESC ( rSelect printing color‡
    ESC ( DSet raster resolution‡
    ESC iTransfer raster image‡
    Printing method control
    ESC ( iSelect MicroWeave print mode
    ESC ( eSelect Ink Drop Size‡
    ESC ( KSet monochrome/color mode‡
    ESC ACKFlush buffers after MicroWeave print mode‡🚫
    ESC ( mSet print method‡🚫
    Printing bar codes
    ESC ( BBar code setup and print
    Data and memory control
    ESC SOH @EJL 1284.4\n@EJL \nExit packet mode
    ESC SOH @EJL 1284.4\n@EJL\n@EJL\nEnter D4 mode
    ESC @Initialize printer
    CANCancel line*
    DELDelete last character in buffer*
    DC1Select printer*🚫
    DC3Deselect printer*🚫
    ESC #Cancel MSB control*
    ESC =Set MSB to 0*
    ESC >Set MSB to 1*
    Deleted commands
    ESC jReverse paper feed*🚫
    ESC iSelect immediate print mode*🚫
    Binary mode commands for ESC . 2
    & ESC . 3 raster graphics modes
    <XFER>Transfer raster graphics data
    <CLR>Clear seed row (Delta Row compression)‡
    <MOVX>Set relative horizontal position
    <MOVY>Set relative vertical position
    <COLR>Select printing color
    <CR>Carriage return to left-most print position
    <EXIT>Exit TIFF compressed mode
    <MOVXBYTE>Set unit to 8 dots
    <MOVXDOT>Set unit to 1 dot
    Remote commands
    (all commands are supported, but
    only a few useful ones are
    implemented.)
    ESC ( RSet remote mode‡
    ESC NUL NUL NULExit remote mode‡
    RSReset printer‡
    FPSet relative left margin‡
    JHSet job name‡
    JSStart job‡
  • Advanced font support

    Specify in advance the fonts you wish to use. 14 different fonts can be specified, each in 2 versions (fixed and proportional fonts), for a total of 28 fonts.

    Use system-installed or custom fonts.

    Text enhancements (strikethrough, underline, highlight, etc.) are supported.


    Fonts examples & character style implementations.
  • Several rendering modes for graphic commands

    Points can be rendered as dots or rectangles. In all cases, the file is vectorized (infinitely scalable).


    Graphic element magnifications. Two ways of rendering.

    Delta Row compression with 720p rendering.
    • NB: Rendering as an image is not yet available, but such a result can be obtained with GhostScript for this task (see examples).

    • Note regarding color rendering: When two CMYK colored objects overlap in printing, then either the object 'on top' will knock out the color of the one underneath it, or the colors of the two objects will mix in the overlapped area. This behaviour can be set using the property overPrint of your PDF viewer. This is mandatory for a good rendering of the PDF files built by Escapy.


    On Okular, since June 2023, the option is under the “Configure Rendering Engines” / “Enable Overprint Preview”
  • Searchable text

    Text remains as text, not as images. This makes content search and indexing possible.

  • Wide range of encodings available

    A major effort has been made to ensure that the essential encodings of this era and more, are also supported by EscaPy. It's easy to add to this list. Contributions are welcome.

    Characters that can be printed in the place of the intervals dedicated to control characters, and international characters (National Replacement Character Set) are also injected into the encoding tables.


    Support for many common encodings.

    NB: It is still necessary to ensure that the fonts used support the selected character sets.

    See details
    • PC437 (US)
    • PC437 Greek
    • PC932 (Japanese)
    • PC850 (Multilingual)
    • PC851 (Greek)
    • PC853 (Turkish)
    • PC855 (Cyrillic)
    • PC860 (Portugal)
    • PC863 (Canada-French)
    • PC865 (Norway)
    • PC852 (East Europe)
    • PC857 (Turkish)
    • PC862 (Hebrew)
    • PC864 (Arabic)
    • PC AR864
    • PC866 (Russian)
    • (Bulgarian ASCII****)
    • PC866 LAT. (Latvian)
    • PC869 (Greek)
    • USSR GOST (Russian)
    • ECMA-94-1
    • KU42 (K.U. Thai)
    • TIS11 (TS 988 Thai)
    • TIS18 (GENERAL Thai)
    • TIS17 (SIC STD. Thai)
    • TIS13 (IBM STD. Thai)
    • TIS16 (SIC OLD Thai)
    • PC861 (Iceland)
    • BRASCII
    • Abicomp
    • MAZOWIA (Poland)
    • Code MJK (CSFR)
    • ISO8859-7 (Latin/Greek)
    • ISO8859-1 (Latin 1)
    • TSM/WIN (Thai system manager)
    • ISO Latin 1T (Turkish)
    • Bulgaria
    • Hebrew 7
    • Hebrew 8
    • Roman 8
    • PC774 (Lithuania)
    • Estonia (Estonia)
    • ISCII
    • PC-ISCII
    • PC APTEC
    • PC708
    • PC720
    • OCR-B
    • ISO Latin 1
    • ISO 8859-2 (ISO Latin 2)
    • ISO Latin 7 (Greek)
  • Page formats

    47 portrait formats and their landscape equivalents are predefined. Custom sizes are also available.

  • User-defined characters support (ESC/P2 only)

    A user can send customized bitmap characters to the printer. A mapping file will be generated to map the received characters to modern unicode codes (see examples).

  • Enhanced reliability thanks to testing (~100%)

    EscaPy is an implementation of a standard made up of over 600 pages covered by almost 300 tests.

    A coverage rate close to 100% eliminates most of the erratic behavior that a non-rigorously tested application can produce.

    However, a coverage rate of 100% does not guarantee that the program rigorously follows the standard, but that its behavior is most often in line with what the developer expected when he designed it.

  • Facilitated development

    The code is fully documented to facilitate maintenance and enhancements.

⚙ Setup

Installation

All operating systems should be supported, although this project is mainly developed for a GNU-Linux system as an everyday computer.

Simple installation from PyPI (beware, the package name is not the project name!):

$ pip install pyscape

Installation from sources :

$ pip install .

Install the project in editable mode for developpers :

$ make install
# Or
$ pip install -e .[dev]

Installation on Debian :

apt install ./escapy_1.0.0-2_all.deb

Usage

$ escapy -h
usage: [-h] [--pins [PINS]] [--single_sheets | --no-single_sheets] [-o [OUTPUT]]
[-c [CONFIG]] [-db [USERDEF_DB_FILEPATH]] [-v]
esc_prn
positional arguments:
esc_prn ESC raw printer file. - to read from stdin.
options:
-h, --help show this help message and exit
--pins [PINS] number of needles of the print head (9, 24, 48). Leave it unsetfor ESCP2 modern printers. (default: unset)
--single_sheets, --no-single_sheets
single-sheets or continuous paper. (default: single-sheets)
-o [OUTPUT], --output [OUTPUT]
PDF output file. - to write on stdout. (default: output.pdf)
-c [CONFIG], --config [CONFIG]
configuration file to use. (default: ./escapy.conf,
~/.local/share/escapy/escapy.conf)
-db [USERDEF_DB_FILEPATH], --userdef_db_filepath [USERDEF_DB_FILEPATH]
mappings between user-defined chararacter codes and unicode.
(default: ./user_defined_mapping.json)
-v, --version show program's version number and exit

NB : The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

Examples

Standard input/output streams are active, so it is possible to chain tools :

$ cat my_file.prn | escapy - -o - > my_pdf.pdf

For example, to convert the generated PDF into a TIFF image with GhostScript :

$ cat my_file.prn | escapy - -o - | \
gs -dBATCH -dNOPAUSE -dSAFER \
-dNoSeparationFiles -dSimulateOverprint=true -sDEVICE=tiffsep -r720 \
-sOutputFile=out-%d.tiff -

📰 Configuration file

The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

By default, the escapy.conf file is searched for in the current folder. If it doesn't exist, it is searched for in the standard software configuration folder on your system (see below). This folder is created if it doesn't already exist.

On GNU/Linux systems: ~/.local/share/escapy/, /etc/escapy/escapy.conf

On Windows systems: C:\\Users\\<YOUR_USERNAME>\\AppData\\Local\\escapy

On MacOS systems: /Users/<YOUR_USERNAME>/Library/Application Support/escapy

The default file is in the repository folder: data.

📰 Printer profiles

Profile example:

[colors]
0 = black
[color:black]
display = Black
offset = 120
rgb = #000000
cmyk = 0,0,0,100
[color:black:mono]
offset = 0

Profiles are files stored by default in a profiles folder next to the default configuration file installed on the system (see above).

They contain a section listing the colors used by the printer, as well as a section defining each of these colors as follows.

Expected keys in each color section:

  • rgb: RGB color code (starting with a #);
  • cmyk: CMYK channels (4 coma separated values).

Optional keys:

  • display: Human readable name;
  • offset: Nozzle position adjustement offset (in 1/180th of an inch).

Regarding nozzle offsets:
Most Epson print heads align all color nozzles on the same horizontal line. However, some models use one color as a reference, with the other color nozzles physically offset from it.

We need to compensate for the data generated by the driver in order to determine the correct position of the received colored data.

Depending on whether monochrome or color mode is selected, the range of nozzles may vary. That's why each color can be found in a dedicated monochrome version.

🔤 Fonts

For reasons of licensing and personal preference, EscaPy does not embed fonts (except for a minimal version of Courier and Helvetica).

List of fonts that can be embedded in Epson printers
  • Roman
  • Sans serif
  • Courier
  • Prestige
  • Script
  • OCR-B
  • OCR-A
  • Orator
  • Orator-S
  • Script C

Free fonts a proprietary equivalents :

ProprietaryFree ->
Courier NewLiberation MonoNoto Sans MonoFreeMonoFira Mono, Fira CodeRoboto Mono
Times New RomanLiberation SerifNoto SerifFreeSerifFiraGORoboto Serif
ArialLiberation SansNoto SansFreeSansFira SansRoboto
OCR-A / OCR-B fontsSquare
stroke ends OCR-A & OCR-B
Rounded ends & extended character coverage OCR-B

See also Recursive free font :

Free bitmap-style fonts :

Non-free fonts or fonts with restrictive licenses, often with a very limited character set, but close to the embedded fonts on Epson printers :


Noto, FreeFont and Fira fonts are normally installed on most systems, but can also be installed manually with the following command (on Debian systems and derivatives):

$ apt install fonts-noto fonts-freefont-ttf fonts-firacode

The same goes for Liberation fonts:

$ apt install fonts-liberation

Windows proprietary fonts can be installed with the following command:

$ apt install ttf-mscorefonts-installer

More generally, think of the fnt tool as a package manager for managing and installing fonts.

🅰️ User-defined characters

A JSON file is created and updated when custom characters are found. The user must specify the desired character in the unicode character set. The changes will be applied to the PDF by restarting the software.

Example:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "\ufffd"
}
}

Here, a character is defined under the unique key 83e1a70_1; the character with code 1 in the table is momentarily associated with the undefined character \ufffd (UNDEFINED).

A modification to match this code with the character could be as follows:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "♫"
}
}

By default, the JSON file (user_defined_mapping.json) is created in the current folder, but this can be changed in the configuration file. A folder containing the image of the bitmap character received can also be created by enabling the option images_path in the section [UserDefinedCharacters] of the configuration file.

🈳 Unsupported encodings (Chinese, Japanese, etc.)

The ESC/P and ESC/P2 standards do not seem to support Chinese or Japanese languages (encodings were apparently not provided for). However, some language evolutions (ESC/POS, ESC/P-K, ESC/P J84) and printers do support this. While in theory these languages can be implemented, their documentation remains hard to find and is beyond the scope of the current project. See Wikipedia - ESC variants.

The easiest way to achieve this is to use the printer in graphics mode (raster or bitimage) instead of text mode.

🏆 Acknowledgements

  • The management of modern fonts and their display on our screens would not have been possible without the work of French engineer Pierre Bézier (1910-1999), who also, through his work at Renault, revolutionized computer-aided design (CAD).

  • The Epson-Seiko teams of the 90's deserve our thanks for producing complete documentation of the language interpreted by their printers.

Absence of acknowledgements

Since the 2010s, Epson-Seiko (like so many other brands) tends to no longer publish language evolutions or advanced technical specifications for their machines. The brand tends to consider that this is now an industrial secret and none of your business.

In an ethical world, we wouldn't have to decipher these proprietary protocols. If you too feel that this is not appropriate, then you should consider manufacturers who respect your right to repair/modify what you own.

👏🏻 Contributions

This project is open for any contribution! Any bug report can be posted by opening an issue.

📖 License

EscaPy is distributed under two licenses: one for community use and the other for commercial use.

Community = Free and Open Source

EscaPy is released under the AGPL (Affero General Public License).

Commercial

The aim is to limit the uses integrated into proprietary devices whose vendors do not participate in the project in an equitable way, and who are guilty of any violation of the EscaPy license or of the free software used by EscaPy itself.

If you are interested in this license, please contact us.

Top ⬆️


Built with ❤️ with Document My Project

About

An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs.

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - ysard/escapy: An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs. · GitHub
Skip to content

Repository files navigation

GitHub release (latest SemVer)version on pypipython versions on pypitests statuspython docstring coveragepython test coveragelicenseDonate

EscaPy

EscaPy is a thoroughly tested tool that reliably and almost exhaustively interprets the ESC/P and ESC/P2 command sets defined by Epson (Wikipedia - Epson ESC/P), then converts the data formerly intended for printers into a modern PDF file.

Table of Contents

Open Contents

ℹ️ About the Project

TL;DR: Your DOS system or emulator will be able to produce searchable PDF files. This tool is compatible with files produced by the Libre Printer interface discussed below.

📖 Foreword

Nowadays, older equipment may still be in use in sectors such as medical or industrial (machine tools). While the software of the old days were often designed to use dot-matrix printers exclusively, these printers can break down or can no longer be used due to a lack of consumables available on the market.

As a result, the entire system has to be replaced without justification.

EscaPy generates PDF files from the raw data sent to the printer. Files can therefore be stored permanently, printed on new hardware, indexed by an archiving system (text remains accessible) or simply consulted at any time.

Note that data destined for the printer must be captured in some way. The Libre Printer project accomplishes exactly this task by providing a software and hardware interface pretending to be a printer compatible with older hardware.

🏦 Donations

EscaPy is a project that took ~2 months of full-time work and 12k+ lines including documentation & tests, for its first version. If it has been useful to you in any way and you would like to contribute to its development, please follow the link below, with all thanks :

Donate

1EB6dc6YULzHR4TMqLi5fomZ6wmdP3N5cW

⭐ Features

  • Advanced ESC/P ESC/P2 command set support

    Nearly all commands are supported (text, graphics and barcodes).

    ! See details & coverage of the command set !

    *: Not recommended command.
    ‡: Extended command (added on modern printers)
    ✅: Implemented.
    ❗: Not fully implemented.
    ⬜: Not implemented.
    🚫: Will not be implemented.

    Setting the page format
    ESC ( CSet page length in defined unit
    ESC ( cSet page format
    ESC CSet page length in lines
    ESC C NULSet page length in inches
    ESC NSet bottom margin
    ESC OCancel bottom margin
    ESC QSet right margin
    ESC lSet left margin
    ESC ( SSet paper dimensions‡
    Moving the print position
    CRCarriage return
    LFLine feed
    FFForm feed
    ESC $Set absolute horizontal print position
    ESC ( $Set absolute horizontal print position‡
    ESC \Set relative horizontal print position
    ESC ( /Set relative horizontal print position‡
    ESC ( VSet absolute vertical print position
    ESC ( vSet relative vertical print position
    ESC JAdvance print position vertically
    HTTab horizontally
    VTTab vertically
    ESC fHorizontal/vertical skip*
    BSBackspace*
    Setting the units
    ESC ( USet unit
    ESC 0Select 1/8-inch line spacing
    ESC 2Select 1/6-inch line spacing
    ESC 3Set n/180-inch line spacing
    ESC 3Set n/216-inch line spacing
    ESC +Set n/360-inch line spacing
    ESC ASet n/60-inch line spacing*
    ESC ASet n/72-inch line spacing*
    ESC 1Select 7/72-inch line spacing*
    ESC DSet horizontal tabs
    ESC BSet vertical tabs
    ESC bSet vertical tabs in VFU channels*
    ESC /Select vertical tab channel*
    ESC eSet fixed tab increment*
    ESC aSelect justification*
    Selecting characters
    ESC ( tAssign character table
    ESC tSelect character table
    ESC RSelect an international character set
    ESC &Define user-defined characters
    ESC :Copy ROM to RAM
    ESC %Select user-defined set
    ESC xSelect LQ or draft
    ESC xSelect NLQ or draft
    ESC kSelect typeface
    ESC XSelect font by pitch and point
    ESC cSet horizontal motion index (HMI)
    ESC PSelect 10.5-point, 10-cpi
    ESC PSelect 10-cpi
    ESC MSelect 10.5-point, 12-cpi
    ESC MSelect 12-cpi
    ESC gSelect 10.5-point, 15-cpi
    ESC gSelect 15-cpi
    ESC pTurn proportional mode on/off
    ESC SPSet intercharacter space
    ESC ESelect bold font
    ESC FCancel bold font
    ESC 4Select italic font
    ESC 5Cancel italic font
    ESC !Master select
    ESC GSelect double-strike printing
    ESC HCancel double-strike printing
    ESC -Turn underline on/off
    ESC ( -Select line/score
    ESC SSelect superscript/subscript printing
    ESC TCancel superscript/subscript printing
    ESC qSelect character style
    SISelect condensed printing
    ESC SISelect condensed printing*
    DC2Cancel condensed printing
    SOSelect double-width printing (one line)
    ESC SOSelect double-width printing (one line)*
    DC4Cancel double-width printing (one line)
    ESC WTurn double-width printing on/off
    ESC wTurn double-height printing on/off
    Control-code character printing
    ESC ( ^Print data as characters
    ESC 6Enable printing of upper control codes
    ESC 7Enable upper control codes
    ESC IEnable printing of control codes
    ESC mSelect printing of upper control codes*
    Mechanical control
    ESC EMControl paper loading/ejecting
    ESC UTurn unidirectional mode on/off🚫
    ESC <Unidirectional mode (one line)*🚫
    BELBeeper*🚫
    ESC 8Disable paper-out detector*🚫
    ESC 9Enable paper-out detector*🚫
    ESC sSelect low-speed mode*🚫
    Printing color and graphics
    ESC ( GSelect graphics mode
    ESC . 0 / ESC . 1Print raster graphics
    ESC . 2Enter TIFF RLE compressed mode
    ESC . 3Enter TIFF Delta Row compressed mode‡
    ESC *Select bit image
    ESC ?Reassign bit-image mode*
    ESC KSelect 60-dpi graphics*
    ESC LSelect 120-dpi graphics*
    ESC YSelect 120-dpi, double-speed graphics*
    ESC ZSelect 240-dpi graphics*
    ESC ^Select 60/120-dpi, 9-pin graphics
    ESC rSelect printing color
    ESC ( rSelect printing color‡
    ESC ( DSet raster resolution‡
    ESC iTransfer raster image‡
    Printing method control
    ESC ( iSelect MicroWeave print mode
    ESC ( eSelect Ink Drop Size‡
    ESC ( KSet monochrome/color mode‡
    ESC ACKFlush buffers after MicroWeave print mode‡🚫
    ESC ( mSet print method‡🚫
    Printing bar codes
    ESC ( BBar code setup and print
    Data and memory control
    ESC SOH @EJL 1284.4\n@EJL \nExit packet mode
    ESC SOH @EJL 1284.4\n@EJL\n@EJL\nEnter D4 mode
    ESC @Initialize printer
    CANCancel line*
    DELDelete last character in buffer*
    DC1Select printer*🚫
    DC3Deselect printer*🚫
    ESC #Cancel MSB control*
    ESC =Set MSB to 0*
    ESC >Set MSB to 1*
    Deleted commands
    ESC jReverse paper feed*🚫
    ESC iSelect immediate print mode*🚫
    Binary mode commands for ESC . 2
    & ESC . 3 raster graphics modes
    <XFER>Transfer raster graphics data
    <CLR>Clear seed row (Delta Row compression)‡
    <MOVX>Set relative horizontal position
    <MOVY>Set relative vertical position
    <COLR>Select printing color
    <CR>Carriage return to left-most print position
    <EXIT>Exit TIFF compressed mode
    <MOVXBYTE>Set unit to 8 dots
    <MOVXDOT>Set unit to 1 dot
    Remote commands
    (all commands are supported, but
    only a few useful ones are
    implemented.)
    ESC ( RSet remote mode‡
    ESC NUL NUL NULExit remote mode‡
    RSReset printer‡
    FPSet relative left margin‡
    JHSet job name‡
    JSStart job‡
  • Advanced font support

    Specify in advance the fonts you wish to use. 14 different fonts can be specified, each in 2 versions (fixed and proportional fonts), for a total of 28 fonts.

    Use system-installed or custom fonts.

    Text enhancements (strikethrough, underline, highlight, etc.) are supported.


    Fonts examples & character style implementations.
  • Several rendering modes for graphic commands

    Points can be rendered as dots or rectangles. In all cases, the file is vectorized (infinitely scalable).


    Graphic element magnifications. Two ways of rendering.

    Delta Row compression with 720p rendering.
    • NB: Rendering as an image is not yet available, but such a result can be obtained with GhostScript for this task (see examples).

    • Note regarding color rendering: When two CMYK colored objects overlap in printing, then either the object 'on top' will knock out the color of the one underneath it, or the colors of the two objects will mix in the overlapped area. This behaviour can be set using the property overPrint of your PDF viewer. This is mandatory for a good rendering of the PDF files built by Escapy.


    On Okular, since June 2023, the option is under the “Configure Rendering Engines” / “Enable Overprint Preview”
  • Searchable text

    Text remains as text, not as images. This makes content search and indexing possible.

  • Wide range of encodings available

    A major effort has been made to ensure that the essential encodings of this era and more, are also supported by EscaPy. It's easy to add to this list. Contributions are welcome.

    Characters that can be printed in the place of the intervals dedicated to control characters, and international characters (National Replacement Character Set) are also injected into the encoding tables.


    Support for many common encodings.

    NB: It is still necessary to ensure that the fonts used support the selected character sets.

    See details
    • PC437 (US)
    • PC437 Greek
    • PC932 (Japanese)
    • PC850 (Multilingual)
    • PC851 (Greek)
    • PC853 (Turkish)
    • PC855 (Cyrillic)
    • PC860 (Portugal)
    • PC863 (Canada-French)
    • PC865 (Norway)
    • PC852 (East Europe)
    • PC857 (Turkish)
    • PC862 (Hebrew)
    • PC864 (Arabic)
    • PC AR864
    • PC866 (Russian)
    • (Bulgarian ASCII****)
    • PC866 LAT. (Latvian)
    • PC869 (Greek)
    • USSR GOST (Russian)
    • ECMA-94-1
    • KU42 (K.U. Thai)
    • TIS11 (TS 988 Thai)
    • TIS18 (GENERAL Thai)
    • TIS17 (SIC STD. Thai)
    • TIS13 (IBM STD. Thai)
    • TIS16 (SIC OLD Thai)
    • PC861 (Iceland)
    • BRASCII
    • Abicomp
    • MAZOWIA (Poland)
    • Code MJK (CSFR)
    • ISO8859-7 (Latin/Greek)
    • ISO8859-1 (Latin 1)
    • TSM/WIN (Thai system manager)
    • ISO Latin 1T (Turkish)
    • Bulgaria
    • Hebrew 7
    • Hebrew 8
    • Roman 8
    • PC774 (Lithuania)
    • Estonia (Estonia)
    • ISCII
    • PC-ISCII
    • PC APTEC
    • PC708
    • PC720
    • OCR-B
    • ISO Latin 1
    • ISO 8859-2 (ISO Latin 2)
    • ISO Latin 7 (Greek)
  • Page formats

    47 portrait formats and their landscape equivalents are predefined. Custom sizes are also available.

  • User-defined characters support (ESC/P2 only)

    A user can send customized bitmap characters to the printer. A mapping file will be generated to map the received characters to modern unicode codes (see examples).

  • Enhanced reliability thanks to testing (~100%)

    EscaPy is an implementation of a standard made up of over 600 pages covered by almost 300 tests.

    A coverage rate close to 100% eliminates most of the erratic behavior that a non-rigorously tested application can produce.

    However, a coverage rate of 100% does not guarantee that the program rigorously follows the standard, but that its behavior is most often in line with what the developer expected when he designed it.

  • Facilitated development

    The code is fully documented to facilitate maintenance and enhancements.

⚙ Setup

Installation

All operating systems should be supported, although this project is mainly developed for a GNU-Linux system as an everyday computer.

Simple installation from PyPI (beware, the package name is not the project name!):

$ pip install pyscape

Installation from sources :

$ pip install .

Install the project in editable mode for developpers :

$ make install
# Or
$ pip install -e .[dev]

Installation on Debian :

apt install ./escapy_1.0.0-2_all.deb

Usage

$ escapy -h
usage: [-h] [--pins [PINS]] [--single_sheets | --no-single_sheets] [-o [OUTPUT]]
[-c [CONFIG]] [-db [USERDEF_DB_FILEPATH]] [-v]
esc_prn
positional arguments:
esc_prn ESC raw printer file. - to read from stdin.
options:
-h, --help show this help message and exit
--pins [PINS] number of needles of the print head (9, 24, 48). Leave it unsetfor ESCP2 modern printers. (default: unset)
--single_sheets, --no-single_sheets
single-sheets or continuous paper. (default: single-sheets)
-o [OUTPUT], --output [OUTPUT]
PDF output file. - to write on stdout. (default: output.pdf)
-c [CONFIG], --config [CONFIG]
configuration file to use. (default: ./escapy.conf,
~/.local/share/escapy/escapy.conf)
-db [USERDEF_DB_FILEPATH], --userdef_db_filepath [USERDEF_DB_FILEPATH]
mappings between user-defined chararacter codes and unicode.
(default: ./user_defined_mapping.json)
-v, --version show program's version number and exit

NB : The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

Examples

Standard input/output streams are active, so it is possible to chain tools :

$ cat my_file.prn | escapy - -o - > my_pdf.pdf

For example, to convert the generated PDF into a TIFF image with GhostScript :

$ cat my_file.prn | escapy - -o - | \
gs -dBATCH -dNOPAUSE -dSAFER \
-dNoSeparationFiles -dSimulateOverprint=true -sDEVICE=tiffsep -r720 \
-sOutputFile=out-%d.tiff -

📰 Configuration file

The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

By default, the escapy.conf file is searched for in the current folder. If it doesn't exist, it is searched for in the standard software configuration folder on your system (see below). This folder is created if it doesn't already exist.

On GNU/Linux systems: ~/.local/share/escapy/, /etc/escapy/escapy.conf

On Windows systems: C:\\Users\\<YOUR_USERNAME>\\AppData\\Local\\escapy

On MacOS systems: /Users/<YOUR_USERNAME>/Library/Application Support/escapy

The default file is in the repository folder: data.

📰 Printer profiles

Profile example:

[colors]
0 = black
[color:black]
display = Black
offset = 120
rgb = #000000
cmyk = 0,0,0,100
[color:black:mono]
offset = 0

Profiles are files stored by default in a profiles folder next to the default configuration file installed on the system (see above).

They contain a section listing the colors used by the printer, as well as a section defining each of these colors as follows.

Expected keys in each color section:

  • rgb: RGB color code (starting with a #);
  • cmyk: CMYK channels (4 coma separated values).

Optional keys:

  • display: Human readable name;
  • offset: Nozzle position adjustement offset (in 1/180th of an inch).

Regarding nozzle offsets:
Most Epson print heads align all color nozzles on the same horizontal line. However, some models use one color as a reference, with the other color nozzles physically offset from it.

We need to compensate for the data generated by the driver in order to determine the correct position of the received colored data.

Depending on whether monochrome or color mode is selected, the range of nozzles may vary. That's why each color can be found in a dedicated monochrome version.

🔤 Fonts

For reasons of licensing and personal preference, EscaPy does not embed fonts (except for a minimal version of Courier and Helvetica).

List of fonts that can be embedded in Epson printers
  • Roman
  • Sans serif
  • Courier
  • Prestige
  • Script
  • OCR-B
  • OCR-A
  • Orator
  • Orator-S
  • Script C

Free fonts a proprietary equivalents :

ProprietaryFree ->
Courier NewLiberation MonoNoto Sans MonoFreeMonoFira Mono, Fira CodeRoboto Mono
Times New RomanLiberation SerifNoto SerifFreeSerifFiraGORoboto Serif
ArialLiberation SansNoto SansFreeSansFira SansRoboto
OCR-A / OCR-B fontsSquare
stroke ends OCR-A & OCR-B
Rounded ends & extended character coverage OCR-B

See also Recursive free font :

Free bitmap-style fonts :

Non-free fonts or fonts with restrictive licenses, often with a very limited character set, but close to the embedded fonts on Epson printers :


Noto, FreeFont and Fira fonts are normally installed on most systems, but can also be installed manually with the following command (on Debian systems and derivatives):

$ apt install fonts-noto fonts-freefont-ttf fonts-firacode

The same goes for Liberation fonts:

$ apt install fonts-liberation

Windows proprietary fonts can be installed with the following command:

$ apt install ttf-mscorefonts-installer

More generally, think of the fnt tool as a package manager for managing and installing fonts.

🅰️ User-defined characters

A JSON file is created and updated when custom characters are found. The user must specify the desired character in the unicode character set. The changes will be applied to the PDF by restarting the software.

Example:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "\ufffd"
}
}

Here, a character is defined under the unique key 83e1a70_1; the character with code 1 in the table is momentarily associated with the undefined character \ufffd (UNDEFINED).

A modification to match this code with the character could be as follows:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "♫"
}
}

By default, the JSON file (user_defined_mapping.json) is created in the current folder, but this can be changed in the configuration file. A folder containing the image of the bitmap character received can also be created by enabling the option images_path in the section [UserDefinedCharacters] of the configuration file.

🈳 Unsupported encodings (Chinese, Japanese, etc.)

The ESC/P and ESC/P2 standards do not seem to support Chinese or Japanese languages (encodings were apparently not provided for). However, some language evolutions (ESC/POS, ESC/P-K, ESC/P J84) and printers do support this. While in theory these languages can be implemented, their documentation remains hard to find and is beyond the scope of the current project. See Wikipedia - ESC variants.

The easiest way to achieve this is to use the printer in graphics mode (raster or bitimage) instead of text mode.

🏆 Acknowledgements

  • The management of modern fonts and their display on our screens would not have been possible without the work of French engineer Pierre Bézier (1910-1999), who also, through his work at Renault, revolutionized computer-aided design (CAD).

  • The Epson-Seiko teams of the 90's deserve our thanks for producing complete documentation of the language interpreted by their printers.

Absence of acknowledgements

Since the 2010s, Epson-Seiko (like so many other brands) tends to no longer publish language evolutions or advanced technical specifications for their machines. The brand tends to consider that this is now an industrial secret and none of your business.

In an ethical world, we wouldn't have to decipher these proprietary protocols. If you too feel that this is not appropriate, then you should consider manufacturers who respect your right to repair/modify what you own.

👏🏻 Contributions

This project is open for any contribution! Any bug report can be posted by opening an issue.

📖 License

EscaPy is distributed under two licenses: one for community use and the other for commercial use.

Community = Free and Open Source

EscaPy is released under the AGPL (Affero General Public License).

Commercial

The aim is to limit the uses integrated into proprietary devices whose vendors do not participate in the project in an equitable way, and who are guilty of any violation of the EscaPy license or of the free software used by EscaPy itself.

If you are interested in this license, please contact us.

Top ⬆️


Built with ❤️ with Document My Project

About

An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs.

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - ysard/escapy: An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs. · GitHub
Skip to content

Repository files navigation

GitHub release (latest SemVer)version on pypipython versions on pypitests statuspython docstring coveragepython test coveragelicenseDonate

EscaPy

EscaPy is a thoroughly tested tool that reliably and almost exhaustively interprets the ESC/P and ESC/P2 command sets defined by Epson (Wikipedia - Epson ESC/P), then converts the data formerly intended for printers into a modern PDF file.

Table of Contents

Open Contents

ℹ️ About the Project

TL;DR: Your DOS system or emulator will be able to produce searchable PDF files. This tool is compatible with files produced by the Libre Printer interface discussed below.

📖 Foreword

Nowadays, older equipment may still be in use in sectors such as medical or industrial (machine tools). While the software of the old days were often designed to use dot-matrix printers exclusively, these printers can break down or can no longer be used due to a lack of consumables available on the market.

As a result, the entire system has to be replaced without justification.

EscaPy generates PDF files from the raw data sent to the printer. Files can therefore be stored permanently, printed on new hardware, indexed by an archiving system (text remains accessible) or simply consulted at any time.

Note that data destined for the printer must be captured in some way. The Libre Printer project accomplishes exactly this task by providing a software and hardware interface pretending to be a printer compatible with older hardware.

🏦 Donations

EscaPy is a project that took ~2 months of full-time work and 12k+ lines including documentation & tests, for its first version. If it has been useful to you in any way and you would like to contribute to its development, please follow the link below, with all thanks :

Donate

1EB6dc6YULzHR4TMqLi5fomZ6wmdP3N5cW

⭐ Features

  • Advanced ESC/P ESC/P2 command set support

    Nearly all commands are supported (text, graphics and barcodes).

    ! See details & coverage of the command set !

    *: Not recommended command.
    ‡: Extended command (added on modern printers)
    ✅: Implemented.
    ❗: Not fully implemented.
    ⬜: Not implemented.
    🚫: Will not be implemented.

    Setting the page format
    ESC ( CSet page length in defined unit
    ESC ( cSet page format
    ESC CSet page length in lines
    ESC C NULSet page length in inches
    ESC NSet bottom margin
    ESC OCancel bottom margin
    ESC QSet right margin
    ESC lSet left margin
    ESC ( SSet paper dimensions‡
    Moving the print position
    CRCarriage return
    LFLine feed
    FFForm feed
    ESC $Set absolute horizontal print position
    ESC ( $Set absolute horizontal print position‡
    ESC \Set relative horizontal print position
    ESC ( /Set relative horizontal print position‡
    ESC ( VSet absolute vertical print position
    ESC ( vSet relative vertical print position
    ESC JAdvance print position vertically
    HTTab horizontally
    VTTab vertically
    ESC fHorizontal/vertical skip*
    BSBackspace*
    Setting the units
    ESC ( USet unit
    ESC 0Select 1/8-inch line spacing
    ESC 2Select 1/6-inch line spacing
    ESC 3Set n/180-inch line spacing
    ESC 3Set n/216-inch line spacing
    ESC +Set n/360-inch line spacing
    ESC ASet n/60-inch line spacing*
    ESC ASet n/72-inch line spacing*
    ESC 1Select 7/72-inch line spacing*
    ESC DSet horizontal tabs
    ESC BSet vertical tabs
    ESC bSet vertical tabs in VFU channels*
    ESC /Select vertical tab channel*
    ESC eSet fixed tab increment*
    ESC aSelect justification*
    Selecting characters
    ESC ( tAssign character table
    ESC tSelect character table
    ESC RSelect an international character set
    ESC &Define user-defined characters
    ESC :Copy ROM to RAM
    ESC %Select user-defined set
    ESC xSelect LQ or draft
    ESC xSelect NLQ or draft
    ESC kSelect typeface
    ESC XSelect font by pitch and point
    ESC cSet horizontal motion index (HMI)
    ESC PSelect 10.5-point, 10-cpi
    ESC PSelect 10-cpi
    ESC MSelect 10.5-point, 12-cpi
    ESC MSelect 12-cpi
    ESC gSelect 10.5-point, 15-cpi
    ESC gSelect 15-cpi
    ESC pTurn proportional mode on/off
    ESC SPSet intercharacter space
    ESC ESelect bold font
    ESC FCancel bold font
    ESC 4Select italic font
    ESC 5Cancel italic font
    ESC !Master select
    ESC GSelect double-strike printing
    ESC HCancel double-strike printing
    ESC -Turn underline on/off
    ESC ( -Select line/score
    ESC SSelect superscript/subscript printing
    ESC TCancel superscript/subscript printing
    ESC qSelect character style
    SISelect condensed printing
    ESC SISelect condensed printing*
    DC2Cancel condensed printing
    SOSelect double-width printing (one line)
    ESC SOSelect double-width printing (one line)*
    DC4Cancel double-width printing (one line)
    ESC WTurn double-width printing on/off
    ESC wTurn double-height printing on/off
    Control-code character printing
    ESC ( ^Print data as characters
    ESC 6Enable printing of upper control codes
    ESC 7Enable upper control codes
    ESC IEnable printing of control codes
    ESC mSelect printing of upper control codes*
    Mechanical control
    ESC EMControl paper loading/ejecting
    ESC UTurn unidirectional mode on/off🚫
    ESC <Unidirectional mode (one line)*🚫
    BELBeeper*🚫
    ESC 8Disable paper-out detector*🚫
    ESC 9Enable paper-out detector*🚫
    ESC sSelect low-speed mode*🚫
    Printing color and graphics
    ESC ( GSelect graphics mode
    ESC . 0 / ESC . 1Print raster graphics
    ESC . 2Enter TIFF RLE compressed mode
    ESC . 3Enter TIFF Delta Row compressed mode‡
    ESC *Select bit image
    ESC ?Reassign bit-image mode*
    ESC KSelect 60-dpi graphics*
    ESC LSelect 120-dpi graphics*
    ESC YSelect 120-dpi, double-speed graphics*
    ESC ZSelect 240-dpi graphics*
    ESC ^Select 60/120-dpi, 9-pin graphics
    ESC rSelect printing color
    ESC ( rSelect printing color‡
    ESC ( DSet raster resolution‡
    ESC iTransfer raster image‡
    Printing method control
    ESC ( iSelect MicroWeave print mode
    ESC ( eSelect Ink Drop Size‡
    ESC ( KSet monochrome/color mode‡
    ESC ACKFlush buffers after MicroWeave print mode‡🚫
    ESC ( mSet print method‡🚫
    Printing bar codes
    ESC ( BBar code setup and print
    Data and memory control
    ESC SOH @EJL 1284.4\n@EJL \nExit packet mode
    ESC SOH @EJL 1284.4\n@EJL\n@EJL\nEnter D4 mode
    ESC @Initialize printer
    CANCancel line*
    DELDelete last character in buffer*
    DC1Select printer*🚫
    DC3Deselect printer*🚫
    ESC #Cancel MSB control*
    ESC =Set MSB to 0*
    ESC >Set MSB to 1*
    Deleted commands
    ESC jReverse paper feed*🚫
    ESC iSelect immediate print mode*🚫
    Binary mode commands for ESC . 2
    & ESC . 3 raster graphics modes
    <XFER>Transfer raster graphics data
    <CLR>Clear seed row (Delta Row compression)‡
    <MOVX>Set relative horizontal position
    <MOVY>Set relative vertical position
    <COLR>Select printing color
    <CR>Carriage return to left-most print position
    <EXIT>Exit TIFF compressed mode
    <MOVXBYTE>Set unit to 8 dots
    <MOVXDOT>Set unit to 1 dot
    Remote commands
    (all commands are supported, but
    only a few useful ones are
    implemented.)
    ESC ( RSet remote mode‡
    ESC NUL NUL NULExit remote mode‡
    RSReset printer‡
    FPSet relative left margin‡
    JHSet job name‡
    JSStart job‡
  • Advanced font support

    Specify in advance the fonts you wish to use. 14 different fonts can be specified, each in 2 versions (fixed and proportional fonts), for a total of 28 fonts.

    Use system-installed or custom fonts.

    Text enhancements (strikethrough, underline, highlight, etc.) are supported.


    Fonts examples & character style implementations.
  • Several rendering modes for graphic commands

    Points can be rendered as dots or rectangles. In all cases, the file is vectorized (infinitely scalable).


    Graphic element magnifications. Two ways of rendering.

    Delta Row compression with 720p rendering.
    • NB: Rendering as an image is not yet available, but such a result can be obtained with GhostScript for this task (see examples).

    • Note regarding color rendering: When two CMYK colored objects overlap in printing, then either the object 'on top' will knock out the color of the one underneath it, or the colors of the two objects will mix in the overlapped area. This behaviour can be set using the property overPrint of your PDF viewer. This is mandatory for a good rendering of the PDF files built by Escapy.


    On Okular, since June 2023, the option is under the “Configure Rendering Engines” / “Enable Overprint Preview”
  • Searchable text

    Text remains as text, not as images. This makes content search and indexing possible.

  • Wide range of encodings available

    A major effort has been made to ensure that the essential encodings of this era and more, are also supported by EscaPy. It's easy to add to this list. Contributions are welcome.

    Characters that can be printed in the place of the intervals dedicated to control characters, and international characters (National Replacement Character Set) are also injected into the encoding tables.


    Support for many common encodings.

    NB: It is still necessary to ensure that the fonts used support the selected character sets.

    See details
    • PC437 (US)
    • PC437 Greek
    • PC932 (Japanese)
    • PC850 (Multilingual)
    • PC851 (Greek)
    • PC853 (Turkish)
    • PC855 (Cyrillic)
    • PC860 (Portugal)
    • PC863 (Canada-French)
    • PC865 (Norway)
    • PC852 (East Europe)
    • PC857 (Turkish)
    • PC862 (Hebrew)
    • PC864 (Arabic)
    • PC AR864
    • PC866 (Russian)
    • (Bulgarian ASCII****)
    • PC866 LAT. (Latvian)
    • PC869 (Greek)
    • USSR GOST (Russian)
    • ECMA-94-1
    • KU42 (K.U. Thai)
    • TIS11 (TS 988 Thai)
    • TIS18 (GENERAL Thai)
    • TIS17 (SIC STD. Thai)
    • TIS13 (IBM STD. Thai)
    • TIS16 (SIC OLD Thai)
    • PC861 (Iceland)
    • BRASCII
    • Abicomp
    • MAZOWIA (Poland)
    • Code MJK (CSFR)
    • ISO8859-7 (Latin/Greek)
    • ISO8859-1 (Latin 1)
    • TSM/WIN (Thai system manager)
    • ISO Latin 1T (Turkish)
    • Bulgaria
    • Hebrew 7
    • Hebrew 8
    • Roman 8
    • PC774 (Lithuania)
    • Estonia (Estonia)
    • ISCII
    • PC-ISCII
    • PC APTEC
    • PC708
    • PC720
    • OCR-B
    • ISO Latin 1
    • ISO 8859-2 (ISO Latin 2)
    • ISO Latin 7 (Greek)
  • Page formats

    47 portrait formats and their landscape equivalents are predefined. Custom sizes are also available.

  • User-defined characters support (ESC/P2 only)

    A user can send customized bitmap characters to the printer. A mapping file will be generated to map the received characters to modern unicode codes (see examples).

  • Enhanced reliability thanks to testing (~100%)

    EscaPy is an implementation of a standard made up of over 600 pages covered by almost 300 tests.

    A coverage rate close to 100% eliminates most of the erratic behavior that a non-rigorously tested application can produce.

    However, a coverage rate of 100% does not guarantee that the program rigorously follows the standard, but that its behavior is most often in line with what the developer expected when he designed it.

  • Facilitated development

    The code is fully documented to facilitate maintenance and enhancements.

⚙ Setup

Installation

All operating systems should be supported, although this project is mainly developed for a GNU-Linux system as an everyday computer.

Simple installation from PyPI (beware, the package name is not the project name!):

$ pip install pyscape

Installation from sources :

$ pip install .

Install the project in editable mode for developpers :

$ make install
# Or
$ pip install -e .[dev]

Installation on Debian :

apt install ./escapy_1.0.0-2_all.deb

Usage

$ escapy -h
usage: [-h] [--pins [PINS]] [--single_sheets | --no-single_sheets] [-o [OUTPUT]]
[-c [CONFIG]] [-db [USERDEF_DB_FILEPATH]] [-v]
esc_prn
positional arguments:
esc_prn ESC raw printer file. - to read from stdin.
options:
-h, --help show this help message and exit
--pins [PINS] number of needles of the print head (9, 24, 48). Leave it unsetfor ESCP2 modern printers. (default: unset)
--single_sheets, --no-single_sheets
single-sheets or continuous paper. (default: single-sheets)
-o [OUTPUT], --output [OUTPUT]
PDF output file. - to write on stdout. (default: output.pdf)
-c [CONFIG], --config [CONFIG]
configuration file to use. (default: ./escapy.conf,
~/.local/share/escapy/escapy.conf)
-db [USERDEF_DB_FILEPATH], --userdef_db_filepath [USERDEF_DB_FILEPATH]
mappings between user-defined chararacter codes and unicode.
(default: ./user_defined_mapping.json)
-v, --version show program's version number and exit

NB : The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

Examples

Standard input/output streams are active, so it is possible to chain tools :

$ cat my_file.prn | escapy - -o - > my_pdf.pdf

For example, to convert the generated PDF into a TIFF image with GhostScript :

$ cat my_file.prn | escapy - -o - | \
gs -dBATCH -dNOPAUSE -dSAFER \
-dNoSeparationFiles -dSimulateOverprint=true -sDEVICE=tiffsep -r720 \
-sOutputFile=out-%d.tiff -

📰 Configuration file

The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

By default, the escapy.conf file is searched for in the current folder. If it doesn't exist, it is searched for in the standard software configuration folder on your system (see below). This folder is created if it doesn't already exist.

On GNU/Linux systems: ~/.local/share/escapy/, /etc/escapy/escapy.conf

On Windows systems: C:\\Users\\<YOUR_USERNAME>\\AppData\\Local\\escapy

On MacOS systems: /Users/<YOUR_USERNAME>/Library/Application Support/escapy

The default file is in the repository folder: data.

📰 Printer profiles

Profile example:

[colors]
0 = black
[color:black]
display = Black
offset = 120
rgb = #000000
cmyk = 0,0,0,100
[color:black:mono]
offset = 0

Profiles are files stored by default in a profiles folder next to the default configuration file installed on the system (see above).

They contain a section listing the colors used by the printer, as well as a section defining each of these colors as follows.

Expected keys in each color section:

  • rgb: RGB color code (starting with a #);
  • cmyk: CMYK channels (4 coma separated values).

Optional keys:

  • display: Human readable name;
  • offset: Nozzle position adjustement offset (in 1/180th of an inch).

Regarding nozzle offsets:
Most Epson print heads align all color nozzles on the same horizontal line. However, some models use one color as a reference, with the other color nozzles physically offset from it.

We need to compensate for the data generated by the driver in order to determine the correct position of the received colored data.

Depending on whether monochrome or color mode is selected, the range of nozzles may vary. That's why each color can be found in a dedicated monochrome version.

🔤 Fonts

For reasons of licensing and personal preference, EscaPy does not embed fonts (except for a minimal version of Courier and Helvetica).

List of fonts that can be embedded in Epson printers
  • Roman
  • Sans serif
  • Courier
  • Prestige
  • Script
  • OCR-B
  • OCR-A
  • Orator
  • Orator-S
  • Script C

Free fonts a proprietary equivalents :

ProprietaryFree ->
Courier NewLiberation MonoNoto Sans MonoFreeMonoFira Mono, Fira CodeRoboto Mono
Times New RomanLiberation SerifNoto SerifFreeSerifFiraGORoboto Serif
ArialLiberation SansNoto SansFreeSansFira SansRoboto
OCR-A / OCR-B fontsSquare
stroke ends OCR-A & OCR-B
Rounded ends & extended character coverage OCR-B

See also Recursive free font :

Free bitmap-style fonts :

Non-free fonts or fonts with restrictive licenses, often with a very limited character set, but close to the embedded fonts on Epson printers :


Noto, FreeFont and Fira fonts are normally installed on most systems, but can also be installed manually with the following command (on Debian systems and derivatives):

$ apt install fonts-noto fonts-freefont-ttf fonts-firacode

The same goes for Liberation fonts:

$ apt install fonts-liberation

Windows proprietary fonts can be installed with the following command:

$ apt install ttf-mscorefonts-installer

More generally, think of the fnt tool as a package manager for managing and installing fonts.

🅰️ User-defined characters

A JSON file is created and updated when custom characters are found. The user must specify the desired character in the unicode character set. The changes will be applied to the PDF by restarting the software.

Example:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "\ufffd"
}
}

Here, a character is defined under the unique key 83e1a70_1; the character with code 1 in the table is momentarily associated with the undefined character \ufffd (UNDEFINED).

A modification to match this code with the character could be as follows:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "♫"
}
}

By default, the JSON file (user_defined_mapping.json) is created in the current folder, but this can be changed in the configuration file. A folder containing the image of the bitmap character received can also be created by enabling the option images_path in the section [UserDefinedCharacters] of the configuration file.

🈳 Unsupported encodings (Chinese, Japanese, etc.)

The ESC/P and ESC/P2 standards do not seem to support Chinese or Japanese languages (encodings were apparently not provided for). However, some language evolutions (ESC/POS, ESC/P-K, ESC/P J84) and printers do support this. While in theory these languages can be implemented, their documentation remains hard to find and is beyond the scope of the current project. See Wikipedia - ESC variants.

The easiest way to achieve this is to use the printer in graphics mode (raster or bitimage) instead of text mode.

🏆 Acknowledgements

  • The management of modern fonts and their display on our screens would not have been possible without the work of French engineer Pierre Bézier (1910-1999), who also, through his work at Renault, revolutionized computer-aided design (CAD).

  • The Epson-Seiko teams of the 90's deserve our thanks for producing complete documentation of the language interpreted by their printers.

Absence of acknowledgements

Since the 2010s, Epson-Seiko (like so many other brands) tends to no longer publish language evolutions or advanced technical specifications for their machines. The brand tends to consider that this is now an industrial secret and none of your business.

In an ethical world, we wouldn't have to decipher these proprietary protocols. If you too feel that this is not appropriate, then you should consider manufacturers who respect your right to repair/modify what you own.

👏🏻 Contributions

This project is open for any contribution! Any bug report can be posted by opening an issue.

📖 License

EscaPy is distributed under two licenses: one for community use and the other for commercial use.

Community = Free and Open Source

EscaPy is released under the AGPL (Affero General Public License).

Commercial

The aim is to limit the uses integrated into proprietary devices whose vendors do not participate in the project in an equitable way, and who are guilty of any violation of the EscaPy license or of the free software used by EscaPy itself.

If you are interested in this license, please contact us.

Top ⬆️


Built with ❤️ with Document My Project

About

An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs.

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' GitHub - ysard/escapy: An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs. · GitHub
Skip to content

Repository files navigation

GitHub release (latest SemVer)version on pypipython versions on pypitests statuspython docstring coveragepython test coveragelicenseDonate

EscaPy

EscaPy is a thoroughly tested tool that reliably and almost exhaustively interprets the ESC/P and ESC/P2 command sets defined by Epson (Wikipedia - Epson ESC/P), then converts the data formerly intended for printers into a modern PDF file.

Table of Contents

Open Contents

ℹ️ About the Project

TL;DR: Your DOS system or emulator will be able to produce searchable PDF files. This tool is compatible with files produced by the Libre Printer interface discussed below.

📖 Foreword

Nowadays, older equipment may still be in use in sectors such as medical or industrial (machine tools). While the software of the old days were often designed to use dot-matrix printers exclusively, these printers can break down or can no longer be used due to a lack of consumables available on the market.

As a result, the entire system has to be replaced without justification.

EscaPy generates PDF files from the raw data sent to the printer. Files can therefore be stored permanently, printed on new hardware, indexed by an archiving system (text remains accessible) or simply consulted at any time.

Note that data destined for the printer must be captured in some way. The Libre Printer project accomplishes exactly this task by providing a software and hardware interface pretending to be a printer compatible with older hardware.

🏦 Donations

EscaPy is a project that took ~2 months of full-time work and 12k+ lines including documentation & tests, for its first version. If it has been useful to you in any way and you would like to contribute to its development, please follow the link below, with all thanks :

Donate

1EB6dc6YULzHR4TMqLi5fomZ6wmdP3N5cW

⭐ Features

  • Advanced ESC/P ESC/P2 command set support

    Nearly all commands are supported (text, graphics and barcodes).

    ! See details & coverage of the command set !

    *: Not recommended command.
    ‡: Extended command (added on modern printers)
    ✅: Implemented.
    ❗: Not fully implemented.
    ⬜: Not implemented.
    🚫: Will not be implemented.

    Setting the page format
    ESC ( CSet page length in defined unit
    ESC ( cSet page format
    ESC CSet page length in lines
    ESC C NULSet page length in inches
    ESC NSet bottom margin
    ESC OCancel bottom margin
    ESC QSet right margin
    ESC lSet left margin
    ESC ( SSet paper dimensions‡
    Moving the print position
    CRCarriage return
    LFLine feed
    FFForm feed
    ESC $Set absolute horizontal print position
    ESC ( $Set absolute horizontal print position‡
    ESC \Set relative horizontal print position
    ESC ( /Set relative horizontal print position‡
    ESC ( VSet absolute vertical print position
    ESC ( vSet relative vertical print position
    ESC JAdvance print position vertically
    HTTab horizontally
    VTTab vertically
    ESC fHorizontal/vertical skip*
    BSBackspace*
    Setting the units
    ESC ( USet unit
    ESC 0Select 1/8-inch line spacing
    ESC 2Select 1/6-inch line spacing
    ESC 3Set n/180-inch line spacing
    ESC 3Set n/216-inch line spacing
    ESC +Set n/360-inch line spacing
    ESC ASet n/60-inch line spacing*
    ESC ASet n/72-inch line spacing*
    ESC 1Select 7/72-inch line spacing*
    ESC DSet horizontal tabs
    ESC BSet vertical tabs
    ESC bSet vertical tabs in VFU channels*
    ESC /Select vertical tab channel*
    ESC eSet fixed tab increment*
    ESC aSelect justification*
    Selecting characters
    ESC ( tAssign character table
    ESC tSelect character table
    ESC RSelect an international character set
    ESC &Define user-defined characters
    ESC :Copy ROM to RAM
    ESC %Select user-defined set
    ESC xSelect LQ or draft
    ESC xSelect NLQ or draft
    ESC kSelect typeface
    ESC XSelect font by pitch and point
    ESC cSet horizontal motion index (HMI)
    ESC PSelect 10.5-point, 10-cpi
    ESC PSelect 10-cpi
    ESC MSelect 10.5-point, 12-cpi
    ESC MSelect 12-cpi
    ESC gSelect 10.5-point, 15-cpi
    ESC gSelect 15-cpi
    ESC pTurn proportional mode on/off
    ESC SPSet intercharacter space
    ESC ESelect bold font
    ESC FCancel bold font
    ESC 4Select italic font
    ESC 5Cancel italic font
    ESC !Master select
    ESC GSelect double-strike printing
    ESC HCancel double-strike printing
    ESC -Turn underline on/off
    ESC ( -Select line/score
    ESC SSelect superscript/subscript printing
    ESC TCancel superscript/subscript printing
    ESC qSelect character style
    SISelect condensed printing
    ESC SISelect condensed printing*
    DC2Cancel condensed printing
    SOSelect double-width printing (one line)
    ESC SOSelect double-width printing (one line)*
    DC4Cancel double-width printing (one line)
    ESC WTurn double-width printing on/off
    ESC wTurn double-height printing on/off
    Control-code character printing
    ESC ( ^Print data as characters
    ESC 6Enable printing of upper control codes
    ESC 7Enable upper control codes
    ESC IEnable printing of control codes
    ESC mSelect printing of upper control codes*
    Mechanical control
    ESC EMControl paper loading/ejecting
    ESC UTurn unidirectional mode on/off🚫
    ESC <Unidirectional mode (one line)*🚫
    BELBeeper*🚫
    ESC 8Disable paper-out detector*🚫
    ESC 9Enable paper-out detector*🚫
    ESC sSelect low-speed mode*🚫
    Printing color and graphics
    ESC ( GSelect graphics mode
    ESC . 0 / ESC . 1Print raster graphics
    ESC . 2Enter TIFF RLE compressed mode
    ESC . 3Enter TIFF Delta Row compressed mode‡
    ESC *Select bit image
    ESC ?Reassign bit-image mode*
    ESC KSelect 60-dpi graphics*
    ESC LSelect 120-dpi graphics*
    ESC YSelect 120-dpi, double-speed graphics*
    ESC ZSelect 240-dpi graphics*
    ESC ^Select 60/120-dpi, 9-pin graphics
    ESC rSelect printing color
    ESC ( rSelect printing color‡
    ESC ( DSet raster resolution‡
    ESC iTransfer raster image‡
    Printing method control
    ESC ( iSelect MicroWeave print mode
    ESC ( eSelect Ink Drop Size‡
    ESC ( KSet monochrome/color mode‡
    ESC ACKFlush buffers after MicroWeave print mode‡🚫
    ESC ( mSet print method‡🚫
    Printing bar codes
    ESC ( BBar code setup and print
    Data and memory control
    ESC SOH @EJL 1284.4\n@EJL \nExit packet mode
    ESC SOH @EJL 1284.4\n@EJL\n@EJL\nEnter D4 mode
    ESC @Initialize printer
    CANCancel line*
    DELDelete last character in buffer*
    DC1Select printer*🚫
    DC3Deselect printer*🚫
    ESC #Cancel MSB control*
    ESC =Set MSB to 0*
    ESC >Set MSB to 1*
    Deleted commands
    ESC jReverse paper feed*🚫
    ESC iSelect immediate print mode*🚫
    Binary mode commands for ESC . 2
    & ESC . 3 raster graphics modes
    <XFER>Transfer raster graphics data
    <CLR>Clear seed row (Delta Row compression)‡
    <MOVX>Set relative horizontal position
    <MOVY>Set relative vertical position
    <COLR>Select printing color
    <CR>Carriage return to left-most print position
    <EXIT>Exit TIFF compressed mode
    <MOVXBYTE>Set unit to 8 dots
    <MOVXDOT>Set unit to 1 dot
    Remote commands
    (all commands are supported, but
    only a few useful ones are
    implemented.)
    ESC ( RSet remote mode‡
    ESC NUL NUL NULExit remote mode‡
    RSReset printer‡
    FPSet relative left margin‡
    JHSet job name‡
    JSStart job‡
  • Advanced font support

    Specify in advance the fonts you wish to use. 14 different fonts can be specified, each in 2 versions (fixed and proportional fonts), for a total of 28 fonts.

    Use system-installed or custom fonts.

    Text enhancements (strikethrough, underline, highlight, etc.) are supported.


    Fonts examples & character style implementations.
  • Several rendering modes for graphic commands

    Points can be rendered as dots or rectangles. In all cases, the file is vectorized (infinitely scalable).


    Graphic element magnifications. Two ways of rendering.

    Delta Row compression with 720p rendering.
    • NB: Rendering as an image is not yet available, but such a result can be obtained with GhostScript for this task (see examples).

    • Note regarding color rendering: When two CMYK colored objects overlap in printing, then either the object 'on top' will knock out the color of the one underneath it, or the colors of the two objects will mix in the overlapped area. This behaviour can be set using the property overPrint of your PDF viewer. This is mandatory for a good rendering of the PDF files built by Escapy.


    On Okular, since June 2023, the option is under the “Configure Rendering Engines” / “Enable Overprint Preview”
  • Searchable text

    Text remains as text, not as images. This makes content search and indexing possible.

  • Wide range of encodings available

    A major effort has been made to ensure that the essential encodings of this era and more, are also supported by EscaPy. It's easy to add to this list. Contributions are welcome.

    Characters that can be printed in the place of the intervals dedicated to control characters, and international characters (National Replacement Character Set) are also injected into the encoding tables.


    Support for many common encodings.

    NB: It is still necessary to ensure that the fonts used support the selected character sets.

    See details
    • PC437 (US)
    • PC437 Greek
    • PC932 (Japanese)
    • PC850 (Multilingual)
    • PC851 (Greek)
    • PC853 (Turkish)
    • PC855 (Cyrillic)
    • PC860 (Portugal)
    • PC863 (Canada-French)
    • PC865 (Norway)
    • PC852 (East Europe)
    • PC857 (Turkish)
    • PC862 (Hebrew)
    • PC864 (Arabic)
    • PC AR864
    • PC866 (Russian)
    • (Bulgarian ASCII****)
    • PC866 LAT. (Latvian)
    • PC869 (Greek)
    • USSR GOST (Russian)
    • ECMA-94-1
    • KU42 (K.U. Thai)
    • TIS11 (TS 988 Thai)
    • TIS18 (GENERAL Thai)
    • TIS17 (SIC STD. Thai)
    • TIS13 (IBM STD. Thai)
    • TIS16 (SIC OLD Thai)
    • PC861 (Iceland)
    • BRASCII
    • Abicomp
    • MAZOWIA (Poland)
    • Code MJK (CSFR)
    • ISO8859-7 (Latin/Greek)
    • ISO8859-1 (Latin 1)
    • TSM/WIN (Thai system manager)
    • ISO Latin 1T (Turkish)
    • Bulgaria
    • Hebrew 7
    • Hebrew 8
    • Roman 8
    • PC774 (Lithuania)
    • Estonia (Estonia)
    • ISCII
    • PC-ISCII
    • PC APTEC
    • PC708
    • PC720
    • OCR-B
    • ISO Latin 1
    • ISO 8859-2 (ISO Latin 2)
    • ISO Latin 7 (Greek)
  • Page formats

    47 portrait formats and their landscape equivalents are predefined. Custom sizes are also available.

  • User-defined characters support (ESC/P2 only)

    A user can send customized bitmap characters to the printer. A mapping file will be generated to map the received characters to modern unicode codes (see examples).

  • Enhanced reliability thanks to testing (~100%)

    EscaPy is an implementation of a standard made up of over 600 pages covered by almost 300 tests.

    A coverage rate close to 100% eliminates most of the erratic behavior that a non-rigorously tested application can produce.

    However, a coverage rate of 100% does not guarantee that the program rigorously follows the standard, but that its behavior is most often in line with what the developer expected when he designed it.

  • Facilitated development

    The code is fully documented to facilitate maintenance and enhancements.

⚙ Setup

Installation

All operating systems should be supported, although this project is mainly developed for a GNU-Linux system as an everyday computer.

Simple installation from PyPI (beware, the package name is not the project name!):

$ pip install pyscape

Installation from sources :

$ pip install .

Install the project in editable mode for developpers :

$ make install
# Or
$ pip install -e .[dev]

Installation on Debian :

apt install ./escapy_1.0.0-2_all.deb

Usage

$ escapy -h
usage: [-h] [--pins [PINS]] [--single_sheets | --no-single_sheets] [-o [OUTPUT]]
[-c [CONFIG]] [-db [USERDEF_DB_FILEPATH]] [-v]
esc_prn
positional arguments:
esc_prn ESC raw printer file. - to read from stdin.
options:
-h, --help show this help message and exit
--pins [PINS] number of needles of the print head (9, 24, 48). Leave it unsetfor ESCP2 modern printers. (default: unset)
--single_sheets, --no-single_sheets
single-sheets or continuous paper. (default: single-sheets)
-o [OUTPUT], --output [OUTPUT]
PDF output file. - to write on stdout. (default: output.pdf)
-c [CONFIG], --config [CONFIG]
configuration file to use. (default: ./escapy.conf,
~/.local/share/escapy/escapy.conf)
-db [USERDEF_DB_FILEPATH], --userdef_db_filepath [USERDEF_DB_FILEPATH]
mappings between user-defined chararacter codes and unicode.
(default: ./user_defined_mapping.json)
-v, --version show program's version number and exit

NB : The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

Examples

Standard input/output streams are active, so it is possible to chain tools :

$ cat my_file.prn | escapy - -o - > my_pdf.pdf

For example, to convert the generated PDF into a TIFF image with GhostScript :

$ cat my_file.prn | escapy - -o - | \
gs -dBATCH -dNOPAUSE -dSAFER \
-dNoSeparationFiles -dSimulateOverprint=true -sDEVICE=tiffsep -r720 \
-sOutputFile=out-%d.tiff -

📰 Configuration file

The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

By default, the escapy.conf file is searched for in the current folder. If it doesn't exist, it is searched for in the standard software configuration folder on your system (see below). This folder is created if it doesn't already exist.

On GNU/Linux systems: ~/.local/share/escapy/, /etc/escapy/escapy.conf

On Windows systems: C:\\Users\\<YOUR_USERNAME>\\AppData\\Local\\escapy

On MacOS systems: /Users/<YOUR_USERNAME>/Library/Application Support/escapy

The default file is in the repository folder: data.

📰 Printer profiles

Profile example:

[colors]
0 = black
[color:black]
display = Black
offset = 120
rgb = #000000
cmyk = 0,0,0,100
[color:black:mono]
offset = 0

Profiles are files stored by default in a profiles folder next to the default configuration file installed on the system (see above).

They contain a section listing the colors used by the printer, as well as a section defining each of these colors as follows.

Expected keys in each color section:

  • rgb: RGB color code (starting with a #);
  • cmyk: CMYK channels (4 coma separated values).

Optional keys:

  • display: Human readable name;
  • offset: Nozzle position adjustement offset (in 1/180th of an inch).

Regarding nozzle offsets:
Most Epson print heads align all color nozzles on the same horizontal line. However, some models use one color as a reference, with the other color nozzles physically offset from it.

We need to compensate for the data generated by the driver in order to determine the correct position of the received colored data.

Depending on whether monochrome or color mode is selected, the range of nozzles may vary. That's why each color can be found in a dedicated monochrome version.

🔤 Fonts

For reasons of licensing and personal preference, EscaPy does not embed fonts (except for a minimal version of Courier and Helvetica).

List of fonts that can be embedded in Epson printers
  • Roman
  • Sans serif
  • Courier
  • Prestige
  • Script
  • OCR-B
  • OCR-A
  • Orator
  • Orator-S
  • Script C

Free fonts a proprietary equivalents :

ProprietaryFree ->
Courier NewLiberation MonoNoto Sans MonoFreeMonoFira Mono, Fira CodeRoboto Mono
Times New RomanLiberation SerifNoto SerifFreeSerifFiraGORoboto Serif
ArialLiberation SansNoto SansFreeSansFira SansRoboto
OCR-A / OCR-B fontsSquare
stroke ends OCR-A & OCR-B
Rounded ends & extended character coverage OCR-B

See also Recursive free font :

Free bitmap-style fonts :

Non-free fonts or fonts with restrictive licenses, often with a very limited character set, but close to the embedded fonts on Epson printers :


Noto, FreeFont and Fira fonts are normally installed on most systems, but can also be installed manually with the following command (on Debian systems and derivatives):

$ apt install fonts-noto fonts-freefont-ttf fonts-firacode

The same goes for Liberation fonts:

$ apt install fonts-liberation

Windows proprietary fonts can be installed with the following command:

$ apt install ttf-mscorefonts-installer

More generally, think of the fnt tool as a package manager for managing and installing fonts.

🅰️ User-defined characters

A JSON file is created and updated when custom characters are found. The user must specify the desired character in the unicode character set. The changes will be applied to the PDF by restarting the software.

Example:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "\ufffd"
}
}

Here, a character is defined under the unique key 83e1a70_1; the character with code 1 in the table is momentarily associated with the undefined character \ufffd (UNDEFINED).

A modification to match this code with the character could be as follows:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "♫"
}
}

By default, the JSON file (user_defined_mapping.json) is created in the current folder, but this can be changed in the configuration file. A folder containing the image of the bitmap character received can also be created by enabling the option images_path in the section [UserDefinedCharacters] of the configuration file.

🈳 Unsupported encodings (Chinese, Japanese, etc.)

The ESC/P and ESC/P2 standards do not seem to support Chinese or Japanese languages (encodings were apparently not provided for). However, some language evolutions (ESC/POS, ESC/P-K, ESC/P J84) and printers do support this. While in theory these languages can be implemented, their documentation remains hard to find and is beyond the scope of the current project. See Wikipedia - ESC variants.

The easiest way to achieve this is to use the printer in graphics mode (raster or bitimage) instead of text mode.

🏆 Acknowledgements

  • The management of modern fonts and their display on our screens would not have been possible without the work of French engineer Pierre Bézier (1910-1999), who also, through his work at Renault, revolutionized computer-aided design (CAD).

  • The Epson-Seiko teams of the 90's deserve our thanks for producing complete documentation of the language interpreted by their printers.

Absence of acknowledgements

Since the 2010s, Epson-Seiko (like so many other brands) tends to no longer publish language evolutions or advanced technical specifications for their machines. The brand tends to consider that this is now an industrial secret and none of your business.

In an ethical world, we wouldn't have to decipher these proprietary protocols. If you too feel that this is not appropriate, then you should consider manufacturers who respect your right to repair/modify what you own.

👏🏻 Contributions

This project is open for any contribution! Any bug report can be posted by opening an issue.

📖 License

EscaPy is distributed under two licenses: one for community use and the other for commercial use.

Community = Free and Open Source

EscaPy is released under the AGPL (Affero General Public License).

Commercial

The aim is to limit the uses integrated into proprietary devices whose vendors do not participate in the project in an equitable way, and who are guilty of any violation of the EscaPy license or of the free software used by EscaPy itself.

If you are interested in this license, please contact us.

Top ⬆️


Built with ❤️ with Document My Project

About

An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs.

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - ysard/escapy: An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs. · GitHub
Skip to content

Repository files navigation

GitHub release (latest SemVer)version on pypipython versions on pypitests statuspython docstring coveragepython test coveragelicenseDonate

EscaPy

EscaPy is a thoroughly tested tool that reliably and almost exhaustively interprets the ESC/P and ESC/P2 command sets defined by Epson (Wikipedia - Epson ESC/P), then converts the data formerly intended for printers into a modern PDF file.

Table of Contents

Open Contents

ℹ️ About the Project

TL;DR: Your DOS system or emulator will be able to produce searchable PDF files. This tool is compatible with files produced by the Libre Printer interface discussed below.

📖 Foreword

Nowadays, older equipment may still be in use in sectors such as medical or industrial (machine tools). While the software of the old days were often designed to use dot-matrix printers exclusively, these printers can break down or can no longer be used due to a lack of consumables available on the market.

As a result, the entire system has to be replaced without justification.

EscaPy generates PDF files from the raw data sent to the printer. Files can therefore be stored permanently, printed on new hardware, indexed by an archiving system (text remains accessible) or simply consulted at any time.

Note that data destined for the printer must be captured in some way. The Libre Printer project accomplishes exactly this task by providing a software and hardware interface pretending to be a printer compatible with older hardware.

🏦 Donations

EscaPy is a project that took ~2 months of full-time work and 12k+ lines including documentation & tests, for its first version. If it has been useful to you in any way and you would like to contribute to its development, please follow the link below, with all thanks :

Donate

1EB6dc6YULzHR4TMqLi5fomZ6wmdP3N5cW

⭐ Features

  • Advanced ESC/P ESC/P2 command set support

    Nearly all commands are supported (text, graphics and barcodes).

    ! See details & coverage of the command set !

    *: Not recommended command.
    ‡: Extended command (added on modern printers)
    ✅: Implemented.
    ❗: Not fully implemented.
    ⬜: Not implemented.
    🚫: Will not be implemented.

    Setting the page format
    ESC ( CSet page length in defined unit
    ESC ( cSet page format
    ESC CSet page length in lines
    ESC C NULSet page length in inches
    ESC NSet bottom margin
    ESC OCancel bottom margin
    ESC QSet right margin
    ESC lSet left margin
    ESC ( SSet paper dimensions‡
    Moving the print position
    CRCarriage return
    LFLine feed
    FFForm feed
    ESC $Set absolute horizontal print position
    ESC ( $Set absolute horizontal print position‡
    ESC \Set relative horizontal print position
    ESC ( /Set relative horizontal print position‡
    ESC ( VSet absolute vertical print position
    ESC ( vSet relative vertical print position
    ESC JAdvance print position vertically
    HTTab horizontally
    VTTab vertically
    ESC fHorizontal/vertical skip*
    BSBackspace*
    Setting the units
    ESC ( USet unit
    ESC 0Select 1/8-inch line spacing
    ESC 2Select 1/6-inch line spacing
    ESC 3Set n/180-inch line spacing
    ESC 3Set n/216-inch line spacing
    ESC +Set n/360-inch line spacing
    ESC ASet n/60-inch line spacing*
    ESC ASet n/72-inch line spacing*
    ESC 1Select 7/72-inch line spacing*
    ESC DSet horizontal tabs
    ESC BSet vertical tabs
    ESC bSet vertical tabs in VFU channels*
    ESC /Select vertical tab channel*
    ESC eSet fixed tab increment*
    ESC aSelect justification*
    Selecting characters
    ESC ( tAssign character table
    ESC tSelect character table
    ESC RSelect an international character set
    ESC &Define user-defined characters
    ESC :Copy ROM to RAM
    ESC %Select user-defined set
    ESC xSelect LQ or draft
    ESC xSelect NLQ or draft
    ESC kSelect typeface
    ESC XSelect font by pitch and point
    ESC cSet horizontal motion index (HMI)
    ESC PSelect 10.5-point, 10-cpi
    ESC PSelect 10-cpi
    ESC MSelect 10.5-point, 12-cpi
    ESC MSelect 12-cpi
    ESC gSelect 10.5-point, 15-cpi
    ESC gSelect 15-cpi
    ESC pTurn proportional mode on/off
    ESC SPSet intercharacter space
    ESC ESelect bold font
    ESC FCancel bold font
    ESC 4Select italic font
    ESC 5Cancel italic font
    ESC !Master select
    ESC GSelect double-strike printing
    ESC HCancel double-strike printing
    ESC -Turn underline on/off
    ESC ( -Select line/score
    ESC SSelect superscript/subscript printing
    ESC TCancel superscript/subscript printing
    ESC qSelect character style
    SISelect condensed printing
    ESC SISelect condensed printing*
    DC2Cancel condensed printing
    SOSelect double-width printing (one line)
    ESC SOSelect double-width printing (one line)*
    DC4Cancel double-width printing (one line)
    ESC WTurn double-width printing on/off
    ESC wTurn double-height printing on/off
    Control-code character printing
    ESC ( ^Print data as characters
    ESC 6Enable printing of upper control codes
    ESC 7Enable upper control codes
    ESC IEnable printing of control codes
    ESC mSelect printing of upper control codes*
    Mechanical control
    ESC EMControl paper loading/ejecting
    ESC UTurn unidirectional mode on/off🚫
    ESC <Unidirectional mode (one line)*🚫
    BELBeeper*🚫
    ESC 8Disable paper-out detector*🚫
    ESC 9Enable paper-out detector*🚫
    ESC sSelect low-speed mode*🚫
    Printing color and graphics
    ESC ( GSelect graphics mode
    ESC . 0 / ESC . 1Print raster graphics
    ESC . 2Enter TIFF RLE compressed mode
    ESC . 3Enter TIFF Delta Row compressed mode‡
    ESC *Select bit image
    ESC ?Reassign bit-image mode*
    ESC KSelect 60-dpi graphics*
    ESC LSelect 120-dpi graphics*
    ESC YSelect 120-dpi, double-speed graphics*
    ESC ZSelect 240-dpi graphics*
    ESC ^Select 60/120-dpi, 9-pin graphics
    ESC rSelect printing color
    ESC ( rSelect printing color‡
    ESC ( DSet raster resolution‡
    ESC iTransfer raster image‡
    Printing method control
    ESC ( iSelect MicroWeave print mode
    ESC ( eSelect Ink Drop Size‡
    ESC ( KSet monochrome/color mode‡
    ESC ACKFlush buffers after MicroWeave print mode‡🚫
    ESC ( mSet print method‡🚫
    Printing bar codes
    ESC ( BBar code setup and print
    Data and memory control
    ESC SOH @EJL 1284.4\n@EJL \nExit packet mode
    ESC SOH @EJL 1284.4\n@EJL\n@EJL\nEnter D4 mode
    ESC @Initialize printer
    CANCancel line*
    DELDelete last character in buffer*
    DC1Select printer*🚫
    DC3Deselect printer*🚫
    ESC #Cancel MSB control*
    ESC =Set MSB to 0*
    ESC >Set MSB to 1*
    Deleted commands
    ESC jReverse paper feed*🚫
    ESC iSelect immediate print mode*🚫
    Binary mode commands for ESC . 2
    & ESC . 3 raster graphics modes
    <XFER>Transfer raster graphics data
    <CLR>Clear seed row (Delta Row compression)‡
    <MOVX>Set relative horizontal position
    <MOVY>Set relative vertical position
    <COLR>Select printing color
    <CR>Carriage return to left-most print position
    <EXIT>Exit TIFF compressed mode
    <MOVXBYTE>Set unit to 8 dots
    <MOVXDOT>Set unit to 1 dot
    Remote commands
    (all commands are supported, but
    only a few useful ones are
    implemented.)
    ESC ( RSet remote mode‡
    ESC NUL NUL NULExit remote mode‡
    RSReset printer‡
    FPSet relative left margin‡
    JHSet job name‡
    JSStart job‡
  • Advanced font support

    Specify in advance the fonts you wish to use. 14 different fonts can be specified, each in 2 versions (fixed and proportional fonts), for a total of 28 fonts.

    Use system-installed or custom fonts.

    Text enhancements (strikethrough, underline, highlight, etc.) are supported.


    Fonts examples & character style implementations.
  • Several rendering modes for graphic commands

    Points can be rendered as dots or rectangles. In all cases, the file is vectorized (infinitely scalable).


    Graphic element magnifications. Two ways of rendering.

    Delta Row compression with 720p rendering.
    • NB: Rendering as an image is not yet available, but such a result can be obtained with GhostScript for this task (see examples).

    • Note regarding color rendering: When two CMYK colored objects overlap in printing, then either the object 'on top' will knock out the color of the one underneath it, or the colors of the two objects will mix in the overlapped area. This behaviour can be set using the property overPrint of your PDF viewer. This is mandatory for a good rendering of the PDF files built by Escapy.


    On Okular, since June 2023, the option is under the “Configure Rendering Engines” / “Enable Overprint Preview”
  • Searchable text

    Text remains as text, not as images. This makes content search and indexing possible.

  • Wide range of encodings available

    A major effort has been made to ensure that the essential encodings of this era and more, are also supported by EscaPy. It's easy to add to this list. Contributions are welcome.

    Characters that can be printed in the place of the intervals dedicated to control characters, and international characters (National Replacement Character Set) are also injected into the encoding tables.


    Support for many common encodings.

    NB: It is still necessary to ensure that the fonts used support the selected character sets.

    See details
    • PC437 (US)
    • PC437 Greek
    • PC932 (Japanese)
    • PC850 (Multilingual)
    • PC851 (Greek)
    • PC853 (Turkish)
    • PC855 (Cyrillic)
    • PC860 (Portugal)
    • PC863 (Canada-French)
    • PC865 (Norway)
    • PC852 (East Europe)
    • PC857 (Turkish)
    • PC862 (Hebrew)
    • PC864 (Arabic)
    • PC AR864
    • PC866 (Russian)
    • (Bulgarian ASCII****)
    • PC866 LAT. (Latvian)
    • PC869 (Greek)
    • USSR GOST (Russian)
    • ECMA-94-1
    • KU42 (K.U. Thai)
    • TIS11 (TS 988 Thai)
    • TIS18 (GENERAL Thai)
    • TIS17 (SIC STD. Thai)
    • TIS13 (IBM STD. Thai)
    • TIS16 (SIC OLD Thai)
    • PC861 (Iceland)
    • BRASCII
    • Abicomp
    • MAZOWIA (Poland)
    • Code MJK (CSFR)
    • ISO8859-7 (Latin/Greek)
    • ISO8859-1 (Latin 1)
    • TSM/WIN (Thai system manager)
    • ISO Latin 1T (Turkish)
    • Bulgaria
    • Hebrew 7
    • Hebrew 8
    • Roman 8
    • PC774 (Lithuania)
    • Estonia (Estonia)
    • ISCII
    • PC-ISCII
    • PC APTEC
    • PC708
    • PC720
    • OCR-B
    • ISO Latin 1
    • ISO 8859-2 (ISO Latin 2)
    • ISO Latin 7 (Greek)
  • Page formats

    47 portrait formats and their landscape equivalents are predefined. Custom sizes are also available.

  • User-defined characters support (ESC/P2 only)

    A user can send customized bitmap characters to the printer. A mapping file will be generated to map the received characters to modern unicode codes (see examples).

  • Enhanced reliability thanks to testing (~100%)

    EscaPy is an implementation of a standard made up of over 600 pages covered by almost 300 tests.

    A coverage rate close to 100% eliminates most of the erratic behavior that a non-rigorously tested application can produce.

    However, a coverage rate of 100% does not guarantee that the program rigorously follows the standard, but that its behavior is most often in line with what the developer expected when he designed it.

  • Facilitated development

    The code is fully documented to facilitate maintenance and enhancements.

⚙ Setup

Installation

All operating systems should be supported, although this project is mainly developed for a GNU-Linux system as an everyday computer.

Simple installation from PyPI (beware, the package name is not the project name!):

$ pip install pyscape

Installation from sources :

$ pip install .

Install the project in editable mode for developpers :

$ make install
# Or
$ pip install -e .[dev]

Installation on Debian :

apt install ./escapy_1.0.0-2_all.deb

Usage

$ escapy -h
usage: [-h] [--pins [PINS]] [--single_sheets | --no-single_sheets] [-o [OUTPUT]]
[-c [CONFIG]] [-db [USERDEF_DB_FILEPATH]] [-v]
esc_prn
positional arguments:
esc_prn ESC raw printer file. - to read from stdin.
options:
-h, --help show this help message and exit
--pins [PINS] number of needles of the print head (9, 24, 48). Leave it unsetfor ESCP2 modern printers. (default: unset)
--single_sheets, --no-single_sheets
single-sheets or continuous paper. (default: single-sheets)
-o [OUTPUT], --output [OUTPUT]
PDF output file. - to write on stdout. (default: output.pdf)
-c [CONFIG], --config [CONFIG]
configuration file to use. (default: ./escapy.conf,
~/.local/share/escapy/escapy.conf)
-db [USERDEF_DB_FILEPATH], --userdef_db_filepath [USERDEF_DB_FILEPATH]
mappings between user-defined chararacter codes and unicode.
(default: ./user_defined_mapping.json)
-v, --version show program's version number and exit

NB : The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

Examples

Standard input/output streams are active, so it is possible to chain tools :

$ cat my_file.prn | escapy - -o - > my_pdf.pdf

For example, to convert the generated PDF into a TIFF image with GhostScript :

$ cat my_file.prn | escapy - -o - | \
gs -dBATCH -dNOPAUSE -dSAFER \
-dNoSeparationFiles -dSimulateOverprint=true -sDEVICE=tiffsep -r720 \
-sOutputFile=out-%d.tiff -

📰 Configuration file

The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

By default, the escapy.conf file is searched for in the current folder. If it doesn't exist, it is searched for in the standard software configuration folder on your system (see below). This folder is created if it doesn't already exist.

On GNU/Linux systems: ~/.local/share/escapy/, /etc/escapy/escapy.conf

On Windows systems: C:\\Users\\<YOUR_USERNAME>\\AppData\\Local\\escapy

On MacOS systems: /Users/<YOUR_USERNAME>/Library/Application Support/escapy

The default file is in the repository folder: data.

📰 Printer profiles

Profile example:

[colors]
0 = black
[color:black]
display = Black
offset = 120
rgb = #000000
cmyk = 0,0,0,100
[color:black:mono]
offset = 0

Profiles are files stored by default in a profiles folder next to the default configuration file installed on the system (see above).

They contain a section listing the colors used by the printer, as well as a section defining each of these colors as follows.

Expected keys in each color section:

  • rgb: RGB color code (starting with a #);
  • cmyk: CMYK channels (4 coma separated values).

Optional keys:

  • display: Human readable name;
  • offset: Nozzle position adjustement offset (in 1/180th of an inch).

Regarding nozzle offsets:
Most Epson print heads align all color nozzles on the same horizontal line. However, some models use one color as a reference, with the other color nozzles physically offset from it.

We need to compensate for the data generated by the driver in order to determine the correct position of the received colored data.

Depending on whether monochrome or color mode is selected, the range of nozzles may vary. That's why each color can be found in a dedicated monochrome version.

🔤 Fonts

For reasons of licensing and personal preference, EscaPy does not embed fonts (except for a minimal version of Courier and Helvetica).

List of fonts that can be embedded in Epson printers
  • Roman
  • Sans serif
  • Courier
  • Prestige
  • Script
  • OCR-B
  • OCR-A
  • Orator
  • Orator-S
  • Script C

Free fonts a proprietary equivalents :

ProprietaryFree ->
Courier NewLiberation MonoNoto Sans MonoFreeMonoFira Mono, Fira CodeRoboto Mono
Times New RomanLiberation SerifNoto SerifFreeSerifFiraGORoboto Serif
ArialLiberation SansNoto SansFreeSansFira SansRoboto
OCR-A / OCR-B fontsSquare
stroke ends OCR-A & OCR-B
Rounded ends & extended character coverage OCR-B

See also Recursive free font :

Free bitmap-style fonts :

Non-free fonts or fonts with restrictive licenses, often with a very limited character set, but close to the embedded fonts on Epson printers :


Noto, FreeFont and Fira fonts are normally installed on most systems, but can also be installed manually with the following command (on Debian systems and derivatives):

$ apt install fonts-noto fonts-freefont-ttf fonts-firacode

The same goes for Liberation fonts:

$ apt install fonts-liberation

Windows proprietary fonts can be installed with the following command:

$ apt install ttf-mscorefonts-installer

More generally, think of the fnt tool as a package manager for managing and installing fonts.

🅰️ User-defined characters

A JSON file is created and updated when custom characters are found. The user must specify the desired character in the unicode character set. The changes will be applied to the PDF by restarting the software.

Example:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "\ufffd"
}
}

Here, a character is defined under the unique key 83e1a70_1; the character with code 1 in the table is momentarily associated with the undefined character \ufffd (UNDEFINED).

A modification to match this code with the character could be as follows:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "♫"
}
}

By default, the JSON file (user_defined_mapping.json) is created in the current folder, but this can be changed in the configuration file. A folder containing the image of the bitmap character received can also be created by enabling the option images_path in the section [UserDefinedCharacters] of the configuration file.

🈳 Unsupported encodings (Chinese, Japanese, etc.)

The ESC/P and ESC/P2 standards do not seem to support Chinese or Japanese languages (encodings were apparently not provided for). However, some language evolutions (ESC/POS, ESC/P-K, ESC/P J84) and printers do support this. While in theory these languages can be implemented, their documentation remains hard to find and is beyond the scope of the current project. See Wikipedia - ESC variants.

The easiest way to achieve this is to use the printer in graphics mode (raster or bitimage) instead of text mode.

🏆 Acknowledgements

  • The management of modern fonts and their display on our screens would not have been possible without the work of French engineer Pierre Bézier (1910-1999), who also, through his work at Renault, revolutionized computer-aided design (CAD).

  • The Epson-Seiko teams of the 90's deserve our thanks for producing complete documentation of the language interpreted by their printers.

Absence of acknowledgements

Since the 2010s, Epson-Seiko (like so many other brands) tends to no longer publish language evolutions or advanced technical specifications for their machines. The brand tends to consider that this is now an industrial secret and none of your business.

In an ethical world, we wouldn't have to decipher these proprietary protocols. If you too feel that this is not appropriate, then you should consider manufacturers who respect your right to repair/modify what you own.

👏🏻 Contributions

This project is open for any contribution! Any bug report can be posted by opening an issue.

📖 License

EscaPy is distributed under two licenses: one for community use and the other for commercial use.

Community = Free and Open Source

EscaPy is released under the AGPL (Affero General Public License).

Commercial

The aim is to limit the uses integrated into proprietary devices whose vendors do not participate in the project in an equitable way, and who are guilty of any violation of the EscaPy license or of the free software used by EscaPy itself.

If you are interested in this license, please contact us.

Top ⬆️


Built with ❤️ with Document My Project

About

An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs.

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - ysard/escapy: An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs. · GitHub
Skip to content

Repository files navigation

GitHub release (latest SemVer)version on pypipython versions on pypitests statuspython docstring coveragepython test coveragelicenseDonate

EscaPy

EscaPy is a thoroughly tested tool that reliably and almost exhaustively interprets the ESC/P and ESC/P2 command sets defined by Epson (Wikipedia - Epson ESC/P), then converts the data formerly intended for printers into a modern PDF file.

Table of Contents

Open Contents

ℹ️ About the Project

TL;DR: Your DOS system or emulator will be able to produce searchable PDF files. This tool is compatible with files produced by the Libre Printer interface discussed below.

📖 Foreword

Nowadays, older equipment may still be in use in sectors such as medical or industrial (machine tools). While the software of the old days were often designed to use dot-matrix printers exclusively, these printers can break down or can no longer be used due to a lack of consumables available on the market.

As a result, the entire system has to be replaced without justification.

EscaPy generates PDF files from the raw data sent to the printer. Files can therefore be stored permanently, printed on new hardware, indexed by an archiving system (text remains accessible) or simply consulted at any time.

Note that data destined for the printer must be captured in some way. The Libre Printer project accomplishes exactly this task by providing a software and hardware interface pretending to be a printer compatible with older hardware.

🏦 Donations

EscaPy is a project that took ~2 months of full-time work and 12k+ lines including documentation & tests, for its first version. If it has been useful to you in any way and you would like to contribute to its development, please follow the link below, with all thanks :

Donate

1EB6dc6YULzHR4TMqLi5fomZ6wmdP3N5cW

⭐ Features

  • Advanced ESC/P ESC/P2 command set support

    Nearly all commands are supported (text, graphics and barcodes).

    ! See details & coverage of the command set !

    *: Not recommended command.
    ‡: Extended command (added on modern printers)
    ✅: Implemented.
    ❗: Not fully implemented.
    ⬜: Not implemented.
    🚫: Will not be implemented.

    Setting the page format
    ESC ( CSet page length in defined unit
    ESC ( cSet page format
    ESC CSet page length in lines
    ESC C NULSet page length in inches
    ESC NSet bottom margin
    ESC OCancel bottom margin
    ESC QSet right margin
    ESC lSet left margin
    ESC ( SSet paper dimensions‡
    Moving the print position
    CRCarriage return
    LFLine feed
    FFForm feed
    ESC $Set absolute horizontal print position
    ESC ( $Set absolute horizontal print position‡
    ESC \Set relative horizontal print position
    ESC ( /Set relative horizontal print position‡
    ESC ( VSet absolute vertical print position
    ESC ( vSet relative vertical print position
    ESC JAdvance print position vertically
    HTTab horizontally
    VTTab vertically
    ESC fHorizontal/vertical skip*
    BSBackspace*
    Setting the units
    ESC ( USet unit
    ESC 0Select 1/8-inch line spacing
    ESC 2Select 1/6-inch line spacing
    ESC 3Set n/180-inch line spacing
    ESC 3Set n/216-inch line spacing
    ESC +Set n/360-inch line spacing
    ESC ASet n/60-inch line spacing*
    ESC ASet n/72-inch line spacing*
    ESC 1Select 7/72-inch line spacing*
    ESC DSet horizontal tabs
    ESC BSet vertical tabs
    ESC bSet vertical tabs in VFU channels*
    ESC /Select vertical tab channel*
    ESC eSet fixed tab increment*
    ESC aSelect justification*
    Selecting characters
    ESC ( tAssign character table
    ESC tSelect character table
    ESC RSelect an international character set
    ESC &Define user-defined characters
    ESC :Copy ROM to RAM
    ESC %Select user-defined set
    ESC xSelect LQ or draft
    ESC xSelect NLQ or draft
    ESC kSelect typeface
    ESC XSelect font by pitch and point
    ESC cSet horizontal motion index (HMI)
    ESC PSelect 10.5-point, 10-cpi
    ESC PSelect 10-cpi
    ESC MSelect 10.5-point, 12-cpi
    ESC MSelect 12-cpi
    ESC gSelect 10.5-point, 15-cpi
    ESC gSelect 15-cpi
    ESC pTurn proportional mode on/off
    ESC SPSet intercharacter space
    ESC ESelect bold font
    ESC FCancel bold font
    ESC 4Select italic font
    ESC 5Cancel italic font
    ESC !Master select
    ESC GSelect double-strike printing
    ESC HCancel double-strike printing
    ESC -Turn underline on/off
    ESC ( -Select line/score
    ESC SSelect superscript/subscript printing
    ESC TCancel superscript/subscript printing
    ESC qSelect character style
    SISelect condensed printing
    ESC SISelect condensed printing*
    DC2Cancel condensed printing
    SOSelect double-width printing (one line)
    ESC SOSelect double-width printing (one line)*
    DC4Cancel double-width printing (one line)
    ESC WTurn double-width printing on/off
    ESC wTurn double-height printing on/off
    Control-code character printing
    ESC ( ^Print data as characters
    ESC 6Enable printing of upper control codes
    ESC 7Enable upper control codes
    ESC IEnable printing of control codes
    ESC mSelect printing of upper control codes*
    Mechanical control
    ESC EMControl paper loading/ejecting
    ESC UTurn unidirectional mode on/off🚫
    ESC <Unidirectional mode (one line)*🚫
    BELBeeper*🚫
    ESC 8Disable paper-out detector*🚫
    ESC 9Enable paper-out detector*🚫
    ESC sSelect low-speed mode*🚫
    Printing color and graphics
    ESC ( GSelect graphics mode
    ESC . 0 / ESC . 1Print raster graphics
    ESC . 2Enter TIFF RLE compressed mode
    ESC . 3Enter TIFF Delta Row compressed mode‡
    ESC *Select bit image
    ESC ?Reassign bit-image mode*
    ESC KSelect 60-dpi graphics*
    ESC LSelect 120-dpi graphics*
    ESC YSelect 120-dpi, double-speed graphics*
    ESC ZSelect 240-dpi graphics*
    ESC ^Select 60/120-dpi, 9-pin graphics
    ESC rSelect printing color
    ESC ( rSelect printing color‡
    ESC ( DSet raster resolution‡
    ESC iTransfer raster image‡
    Printing method control
    ESC ( iSelect MicroWeave print mode
    ESC ( eSelect Ink Drop Size‡
    ESC ( KSet monochrome/color mode‡
    ESC ACKFlush buffers after MicroWeave print mode‡🚫
    ESC ( mSet print method‡🚫
    Printing bar codes
    ESC ( BBar code setup and print
    Data and memory control
    ESC SOH @EJL 1284.4\n@EJL \nExit packet mode
    ESC SOH @EJL 1284.4\n@EJL\n@EJL\nEnter D4 mode
    ESC @Initialize printer
    CANCancel line*
    DELDelete last character in buffer*
    DC1Select printer*🚫
    DC3Deselect printer*🚫
    ESC #Cancel MSB control*
    ESC =Set MSB to 0*
    ESC >Set MSB to 1*
    Deleted commands
    ESC jReverse paper feed*🚫
    ESC iSelect immediate print mode*🚫
    Binary mode commands for ESC . 2
    & ESC . 3 raster graphics modes
    <XFER>Transfer raster graphics data
    <CLR>Clear seed row (Delta Row compression)‡
    <MOVX>Set relative horizontal position
    <MOVY>Set relative vertical position
    <COLR>Select printing color
    <CR>Carriage return to left-most print position
    <EXIT>Exit TIFF compressed mode
    <MOVXBYTE>Set unit to 8 dots
    <MOVXDOT>Set unit to 1 dot
    Remote commands
    (all commands are supported, but
    only a few useful ones are
    implemented.)
    ESC ( RSet remote mode‡
    ESC NUL NUL NULExit remote mode‡
    RSReset printer‡
    FPSet relative left margin‡
    JHSet job name‡
    JSStart job‡
  • Advanced font support

    Specify in advance the fonts you wish to use. 14 different fonts can be specified, each in 2 versions (fixed and proportional fonts), for a total of 28 fonts.

    Use system-installed or custom fonts.

    Text enhancements (strikethrough, underline, highlight, etc.) are supported.


    Fonts examples & character style implementations.
  • Several rendering modes for graphic commands

    Points can be rendered as dots or rectangles. In all cases, the file is vectorized (infinitely scalable).


    Graphic element magnifications. Two ways of rendering.

    Delta Row compression with 720p rendering.
    • NB: Rendering as an image is not yet available, but such a result can be obtained with GhostScript for this task (see examples).

    • Note regarding color rendering: When two CMYK colored objects overlap in printing, then either the object 'on top' will knock out the color of the one underneath it, or the colors of the two objects will mix in the overlapped area. This behaviour can be set using the property overPrint of your PDF viewer. This is mandatory for a good rendering of the PDF files built by Escapy.


    On Okular, since June 2023, the option is under the “Configure Rendering Engines” / “Enable Overprint Preview”
  • Searchable text

    Text remains as text, not as images. This makes content search and indexing possible.

  • Wide range of encodings available

    A major effort has been made to ensure that the essential encodings of this era and more, are also supported by EscaPy. It's easy to add to this list. Contributions are welcome.

    Characters that can be printed in the place of the intervals dedicated to control characters, and international characters (National Replacement Character Set) are also injected into the encoding tables.


    Support for many common encodings.

    NB: It is still necessary to ensure that the fonts used support the selected character sets.

    See details
    • PC437 (US)
    • PC437 Greek
    • PC932 (Japanese)
    • PC850 (Multilingual)
    • PC851 (Greek)
    • PC853 (Turkish)
    • PC855 (Cyrillic)
    • PC860 (Portugal)
    • PC863 (Canada-French)
    • PC865 (Norway)
    • PC852 (East Europe)
    • PC857 (Turkish)
    • PC862 (Hebrew)
    • PC864 (Arabic)
    • PC AR864
    • PC866 (Russian)
    • (Bulgarian ASCII****)
    • PC866 LAT. (Latvian)
    • PC869 (Greek)
    • USSR GOST (Russian)
    • ECMA-94-1
    • KU42 (K.U. Thai)
    • TIS11 (TS 988 Thai)
    • TIS18 (GENERAL Thai)
    • TIS17 (SIC STD. Thai)
    • TIS13 (IBM STD. Thai)
    • TIS16 (SIC OLD Thai)
    • PC861 (Iceland)
    • BRASCII
    • Abicomp
    • MAZOWIA (Poland)
    • Code MJK (CSFR)
    • ISO8859-7 (Latin/Greek)
    • ISO8859-1 (Latin 1)
    • TSM/WIN (Thai system manager)
    • ISO Latin 1T (Turkish)
    • Bulgaria
    • Hebrew 7
    • Hebrew 8
    • Roman 8
    • PC774 (Lithuania)
    • Estonia (Estonia)
    • ISCII
    • PC-ISCII
    • PC APTEC
    • PC708
    • PC720
    • OCR-B
    • ISO Latin 1
    • ISO 8859-2 (ISO Latin 2)
    • ISO Latin 7 (Greek)
  • Page formats

    47 portrait formats and their landscape equivalents are predefined. Custom sizes are also available.

  • User-defined characters support (ESC/P2 only)

    A user can send customized bitmap characters to the printer. A mapping file will be generated to map the received characters to modern unicode codes (see examples).

  • Enhanced reliability thanks to testing (~100%)

    EscaPy is an implementation of a standard made up of over 600 pages covered by almost 300 tests.

    A coverage rate close to 100% eliminates most of the erratic behavior that a non-rigorously tested application can produce.

    However, a coverage rate of 100% does not guarantee that the program rigorously follows the standard, but that its behavior is most often in line with what the developer expected when he designed it.

  • Facilitated development

    The code is fully documented to facilitate maintenance and enhancements.

⚙ Setup

Installation

All operating systems should be supported, although this project is mainly developed for a GNU-Linux system as an everyday computer.

Simple installation from PyPI (beware, the package name is not the project name!):

$ pip install pyscape

Installation from sources :

$ pip install .

Install the project in editable mode for developpers :

$ make install
# Or
$ pip install -e .[dev]

Installation on Debian :

apt install ./escapy_1.0.0-2_all.deb

Usage

$ escapy -h
usage: [-h] [--pins [PINS]] [--single_sheets | --no-single_sheets] [-o [OUTPUT]]
[-c [CONFIG]] [-db [USERDEF_DB_FILEPATH]] [-v]
esc_prn
positional arguments:
esc_prn ESC raw printer file. - to read from stdin.
options:
-h, --help show this help message and exit
--pins [PINS] number of needles of the print head (9, 24, 48). Leave it unsetfor ESCP2 modern printers. (default: unset)
--single_sheets, --no-single_sheets
single-sheets or continuous paper. (default: single-sheets)
-o [OUTPUT], --output [OUTPUT]
PDF output file. - to write on stdout. (default: output.pdf)
-c [CONFIG], --config [CONFIG]
configuration file to use. (default: ./escapy.conf,
~/.local/share/escapy/escapy.conf)
-db [USERDEF_DB_FILEPATH], --userdef_db_filepath [USERDEF_DB_FILEPATH]
mappings between user-defined chararacter codes and unicode.
(default: ./user_defined_mapping.json)
-v, --version show program's version number and exit

NB : The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

Examples

Standard input/output streams are active, so it is possible to chain tools :

$ cat my_file.prn | escapy - -o - > my_pdf.pdf

For example, to convert the generated PDF into a TIFF image with GhostScript :

$ cat my_file.prn | escapy - -o - | \
gs -dBATCH -dNOPAUSE -dSAFER \
-dNoSeparationFiles -dSimulateOverprint=true -sDEVICE=tiffsep -r720 \
-sOutputFile=out-%d.tiff -

📰 Configuration file

The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

By default, the escapy.conf file is searched for in the current folder. If it doesn't exist, it is searched for in the standard software configuration folder on your system (see below). This folder is created if it doesn't already exist.

On GNU/Linux systems: ~/.local/share/escapy/, /etc/escapy/escapy.conf

On Windows systems: C:\\Users\\<YOUR_USERNAME>\\AppData\\Local\\escapy

On MacOS systems: /Users/<YOUR_USERNAME>/Library/Application Support/escapy

The default file is in the repository folder: data.

📰 Printer profiles

Profile example:

[colors]
0 = black
[color:black]
display = Black
offset = 120
rgb = #000000
cmyk = 0,0,0,100
[color:black:mono]
offset = 0

Profiles are files stored by default in a profiles folder next to the default configuration file installed on the system (see above).

They contain a section listing the colors used by the printer, as well as a section defining each of these colors as follows.

Expected keys in each color section:

  • rgb: RGB color code (starting with a #);
  • cmyk: CMYK channels (4 coma separated values).

Optional keys:

  • display: Human readable name;
  • offset: Nozzle position adjustement offset (in 1/180th of an inch).

Regarding nozzle offsets:
Most Epson print heads align all color nozzles on the same horizontal line. However, some models use one color as a reference, with the other color nozzles physically offset from it.

We need to compensate for the data generated by the driver in order to determine the correct position of the received colored data.

Depending on whether monochrome or color mode is selected, the range of nozzles may vary. That's why each color can be found in a dedicated monochrome version.

🔤 Fonts

For reasons of licensing and personal preference, EscaPy does not embed fonts (except for a minimal version of Courier and Helvetica).

List of fonts that can be embedded in Epson printers
  • Roman
  • Sans serif
  • Courier
  • Prestige
  • Script
  • OCR-B
  • OCR-A
  • Orator
  • Orator-S
  • Script C

Free fonts a proprietary equivalents :

ProprietaryFree ->
Courier NewLiberation MonoNoto Sans MonoFreeMonoFira Mono, Fira CodeRoboto Mono
Times New RomanLiberation SerifNoto SerifFreeSerifFiraGORoboto Serif
ArialLiberation SansNoto SansFreeSansFira SansRoboto
OCR-A / OCR-B fontsSquare
stroke ends OCR-A & OCR-B
Rounded ends & extended character coverage OCR-B

See also Recursive free font :

Free bitmap-style fonts :

Non-free fonts or fonts with restrictive licenses, often with a very limited character set, but close to the embedded fonts on Epson printers :


Noto, FreeFont and Fira fonts are normally installed on most systems, but can also be installed manually with the following command (on Debian systems and derivatives):

$ apt install fonts-noto fonts-freefont-ttf fonts-firacode

The same goes for Liberation fonts:

$ apt install fonts-liberation

Windows proprietary fonts can be installed with the following command:

$ apt install ttf-mscorefonts-installer

More generally, think of the fnt tool as a package manager for managing and installing fonts.

🅰️ User-defined characters

A JSON file is created and updated when custom characters are found. The user must specify the desired character in the unicode character set. The changes will be applied to the PDF by restarting the software.

Example:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "\ufffd"
}
}

Here, a character is defined under the unique key 83e1a70_1; the character with code 1 in the table is momentarily associated with the undefined character \ufffd (UNDEFINED).

A modification to match this code with the character could be as follows:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "♫"
}
}

By default, the JSON file (user_defined_mapping.json) is created in the current folder, but this can be changed in the configuration file. A folder containing the image of the bitmap character received can also be created by enabling the option images_path in the section [UserDefinedCharacters] of the configuration file.

🈳 Unsupported encodings (Chinese, Japanese, etc.)

The ESC/P and ESC/P2 standards do not seem to support Chinese or Japanese languages (encodings were apparently not provided for). However, some language evolutions (ESC/POS, ESC/P-K, ESC/P J84) and printers do support this. While in theory these languages can be implemented, their documentation remains hard to find and is beyond the scope of the current project. See Wikipedia - ESC variants.

The easiest way to achieve this is to use the printer in graphics mode (raster or bitimage) instead of text mode.

🏆 Acknowledgements

  • The management of modern fonts and their display on our screens would not have been possible without the work of French engineer Pierre Bézier (1910-1999), who also, through his work at Renault, revolutionized computer-aided design (CAD).

  • The Epson-Seiko teams of the 90's deserve our thanks for producing complete documentation of the language interpreted by their printers.

Absence of acknowledgements

Since the 2010s, Epson-Seiko (like so many other brands) tends to no longer publish language evolutions or advanced technical specifications for their machines. The brand tends to consider that this is now an industrial secret and none of your business.

In an ethical world, we wouldn't have to decipher these proprietary protocols. If you too feel that this is not appropriate, then you should consider manufacturers who respect your right to repair/modify what you own.

👏🏻 Contributions

This project is open for any contribution! Any bug report can be posted by opening an issue.

📖 License

EscaPy is distributed under two licenses: one for community use and the other for commercial use.

Community = Free and Open Source

EscaPy is released under the AGPL (Affero General Public License).

Commercial

The aim is to limit the uses integrated into proprietary devices whose vendors do not participate in the project in an equitable way, and who are guilty of any violation of the EscaPy license or of the free software used by EscaPy itself.

If you are interested in this license, please contact us.

Top ⬆️


Built with ❤️ with Document My Project

About

An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs.

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); GitHub - ysard/escapy: An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs. · GitHub
Skip to content

Repository files navigation

GitHub release (latest SemVer)version on pypipython versions on pypitests statuspython docstring coveragepython test coveragelicenseDonate

EscaPy

EscaPy is a thoroughly tested tool that reliably and almost exhaustively interprets the ESC/P and ESC/P2 command sets defined by Epson (Wikipedia - Epson ESC/P), then converts the data formerly intended for printers into a modern PDF file.

Table of Contents

Open Contents

ℹ️ About the Project

TL;DR: Your DOS system or emulator will be able to produce searchable PDF files. This tool is compatible with files produced by the Libre Printer interface discussed below.

📖 Foreword

Nowadays, older equipment may still be in use in sectors such as medical or industrial (machine tools). While the software of the old days were often designed to use dot-matrix printers exclusively, these printers can break down or can no longer be used due to a lack of consumables available on the market.

As a result, the entire system has to be replaced without justification.

EscaPy generates PDF files from the raw data sent to the printer. Files can therefore be stored permanently, printed on new hardware, indexed by an archiving system (text remains accessible) or simply consulted at any time.

Note that data destined for the printer must be captured in some way. The Libre Printer project accomplishes exactly this task by providing a software and hardware interface pretending to be a printer compatible with older hardware.

🏦 Donations

EscaPy is a project that took ~2 months of full-time work and 12k+ lines including documentation & tests, for its first version. If it has been useful to you in any way and you would like to contribute to its development, please follow the link below, with all thanks :

Donate

1EB6dc6YULzHR4TMqLi5fomZ6wmdP3N5cW

⭐ Features

  • Advanced ESC/P ESC/P2 command set support

    Nearly all commands are supported (text, graphics and barcodes).

    ! See details & coverage of the command set !

    *: Not recommended command.
    ‡: Extended command (added on modern printers)
    ✅: Implemented.
    ❗: Not fully implemented.
    ⬜: Not implemented.
    🚫: Will not be implemented.

    Setting the page format
    ESC ( CSet page length in defined unit
    ESC ( cSet page format
    ESC CSet page length in lines
    ESC C NULSet page length in inches
    ESC NSet bottom margin
    ESC OCancel bottom margin
    ESC QSet right margin
    ESC lSet left margin
    ESC ( SSet paper dimensions‡
    Moving the print position
    CRCarriage return
    LFLine feed
    FFForm feed
    ESC $Set absolute horizontal print position
    ESC ( $Set absolute horizontal print position‡
    ESC \Set relative horizontal print position
    ESC ( /Set relative horizontal print position‡
    ESC ( VSet absolute vertical print position
    ESC ( vSet relative vertical print position
    ESC JAdvance print position vertically
    HTTab horizontally
    VTTab vertically
    ESC fHorizontal/vertical skip*
    BSBackspace*
    Setting the units
    ESC ( USet unit
    ESC 0Select 1/8-inch line spacing
    ESC 2Select 1/6-inch line spacing
    ESC 3Set n/180-inch line spacing
    ESC 3Set n/216-inch line spacing
    ESC +Set n/360-inch line spacing
    ESC ASet n/60-inch line spacing*
    ESC ASet n/72-inch line spacing*
    ESC 1Select 7/72-inch line spacing*
    ESC DSet horizontal tabs
    ESC BSet vertical tabs
    ESC bSet vertical tabs in VFU channels*
    ESC /Select vertical tab channel*
    ESC eSet fixed tab increment*
    ESC aSelect justification*
    Selecting characters
    ESC ( tAssign character table
    ESC tSelect character table
    ESC RSelect an international character set
    ESC &Define user-defined characters
    ESC :Copy ROM to RAM
    ESC %Select user-defined set
    ESC xSelect LQ or draft
    ESC xSelect NLQ or draft
    ESC kSelect typeface
    ESC XSelect font by pitch and point
    ESC cSet horizontal motion index (HMI)
    ESC PSelect 10.5-point, 10-cpi
    ESC PSelect 10-cpi
    ESC MSelect 10.5-point, 12-cpi
    ESC MSelect 12-cpi
    ESC gSelect 10.5-point, 15-cpi
    ESC gSelect 15-cpi
    ESC pTurn proportional mode on/off
    ESC SPSet intercharacter space
    ESC ESelect bold font
    ESC FCancel bold font
    ESC 4Select italic font
    ESC 5Cancel italic font
    ESC !Master select
    ESC GSelect double-strike printing
    ESC HCancel double-strike printing
    ESC -Turn underline on/off
    ESC ( -Select line/score
    ESC SSelect superscript/subscript printing
    ESC TCancel superscript/subscript printing
    ESC qSelect character style
    SISelect condensed printing
    ESC SISelect condensed printing*
    DC2Cancel condensed printing
    SOSelect double-width printing (one line)
    ESC SOSelect double-width printing (one line)*
    DC4Cancel double-width printing (one line)
    ESC WTurn double-width printing on/off
    ESC wTurn double-height printing on/off
    Control-code character printing
    ESC ( ^Print data as characters
    ESC 6Enable printing of upper control codes
    ESC 7Enable upper control codes
    ESC IEnable printing of control codes
    ESC mSelect printing of upper control codes*
    Mechanical control
    ESC EMControl paper loading/ejecting
    ESC UTurn unidirectional mode on/off🚫
    ESC <Unidirectional mode (one line)*🚫
    BELBeeper*🚫
    ESC 8Disable paper-out detector*🚫
    ESC 9Enable paper-out detector*🚫
    ESC sSelect low-speed mode*🚫
    Printing color and graphics
    ESC ( GSelect graphics mode
    ESC . 0 / ESC . 1Print raster graphics
    ESC . 2Enter TIFF RLE compressed mode
    ESC . 3Enter TIFF Delta Row compressed mode‡
    ESC *Select bit image
    ESC ?Reassign bit-image mode*
    ESC KSelect 60-dpi graphics*
    ESC LSelect 120-dpi graphics*
    ESC YSelect 120-dpi, double-speed graphics*
    ESC ZSelect 240-dpi graphics*
    ESC ^Select 60/120-dpi, 9-pin graphics
    ESC rSelect printing color
    ESC ( rSelect printing color‡
    ESC ( DSet raster resolution‡
    ESC iTransfer raster image‡
    Printing method control
    ESC ( iSelect MicroWeave print mode
    ESC ( eSelect Ink Drop Size‡
    ESC ( KSet monochrome/color mode‡
    ESC ACKFlush buffers after MicroWeave print mode‡🚫
    ESC ( mSet print method‡🚫
    Printing bar codes
    ESC ( BBar code setup and print
    Data and memory control
    ESC SOH @EJL 1284.4\n@EJL \nExit packet mode
    ESC SOH @EJL 1284.4\n@EJL\n@EJL\nEnter D4 mode
    ESC @Initialize printer
    CANCancel line*
    DELDelete last character in buffer*
    DC1Select printer*🚫
    DC3Deselect printer*🚫
    ESC #Cancel MSB control*
    ESC =Set MSB to 0*
    ESC >Set MSB to 1*
    Deleted commands
    ESC jReverse paper feed*🚫
    ESC iSelect immediate print mode*🚫
    Binary mode commands for ESC . 2
    & ESC . 3 raster graphics modes
    <XFER>Transfer raster graphics data
    <CLR>Clear seed row (Delta Row compression)‡
    <MOVX>Set relative horizontal position
    <MOVY>Set relative vertical position
    <COLR>Select printing color
    <CR>Carriage return to left-most print position
    <EXIT>Exit TIFF compressed mode
    <MOVXBYTE>Set unit to 8 dots
    <MOVXDOT>Set unit to 1 dot
    Remote commands
    (all commands are supported, but
    only a few useful ones are
    implemented.)
    ESC ( RSet remote mode‡
    ESC NUL NUL NULExit remote mode‡
    RSReset printer‡
    FPSet relative left margin‡
    JHSet job name‡
    JSStart job‡
  • Advanced font support

    Specify in advance the fonts you wish to use. 14 different fonts can be specified, each in 2 versions (fixed and proportional fonts), for a total of 28 fonts.

    Use system-installed or custom fonts.

    Text enhancements (strikethrough, underline, highlight, etc.) are supported.


    Fonts examples & character style implementations.
  • Several rendering modes for graphic commands

    Points can be rendered as dots or rectangles. In all cases, the file is vectorized (infinitely scalable).


    Graphic element magnifications. Two ways of rendering.

    Delta Row compression with 720p rendering.
    • NB: Rendering as an image is not yet available, but such a result can be obtained with GhostScript for this task (see examples).

    • Note regarding color rendering: When two CMYK colored objects overlap in printing, then either the object 'on top' will knock out the color of the one underneath it, or the colors of the two objects will mix in the overlapped area. This behaviour can be set using the property overPrint of your PDF viewer. This is mandatory for a good rendering of the PDF files built by Escapy.


    On Okular, since June 2023, the option is under the “Configure Rendering Engines” / “Enable Overprint Preview”
  • Searchable text

    Text remains as text, not as images. This makes content search and indexing possible.

  • Wide range of encodings available

    A major effort has been made to ensure that the essential encodings of this era and more, are also supported by EscaPy. It's easy to add to this list. Contributions are welcome.

    Characters that can be printed in the place of the intervals dedicated to control characters, and international characters (National Replacement Character Set) are also injected into the encoding tables.


    Support for many common encodings.

    NB: It is still necessary to ensure that the fonts used support the selected character sets.

    See details
    • PC437 (US)
    • PC437 Greek
    • PC932 (Japanese)
    • PC850 (Multilingual)
    • PC851 (Greek)
    • PC853 (Turkish)
    • PC855 (Cyrillic)
    • PC860 (Portugal)
    • PC863 (Canada-French)
    • PC865 (Norway)
    • PC852 (East Europe)
    • PC857 (Turkish)
    • PC862 (Hebrew)
    • PC864 (Arabic)
    • PC AR864
    • PC866 (Russian)
    • (Bulgarian ASCII****)
    • PC866 LAT. (Latvian)
    • PC869 (Greek)
    • USSR GOST (Russian)
    • ECMA-94-1
    • KU42 (K.U. Thai)
    • TIS11 (TS 988 Thai)
    • TIS18 (GENERAL Thai)
    • TIS17 (SIC STD. Thai)
    • TIS13 (IBM STD. Thai)
    • TIS16 (SIC OLD Thai)
    • PC861 (Iceland)
    • BRASCII
    • Abicomp
    • MAZOWIA (Poland)
    • Code MJK (CSFR)
    • ISO8859-7 (Latin/Greek)
    • ISO8859-1 (Latin 1)
    • TSM/WIN (Thai system manager)
    • ISO Latin 1T (Turkish)
    • Bulgaria
    • Hebrew 7
    • Hebrew 8
    • Roman 8
    • PC774 (Lithuania)
    • Estonia (Estonia)
    • ISCII
    • PC-ISCII
    • PC APTEC
    • PC708
    • PC720
    • OCR-B
    • ISO Latin 1
    • ISO 8859-2 (ISO Latin 2)
    • ISO Latin 7 (Greek)
  • Page formats

    47 portrait formats and their landscape equivalents are predefined. Custom sizes are also available.

  • User-defined characters support (ESC/P2 only)

    A user can send customized bitmap characters to the printer. A mapping file will be generated to map the received characters to modern unicode codes (see examples).

  • Enhanced reliability thanks to testing (~100%)

    EscaPy is an implementation of a standard made up of over 600 pages covered by almost 300 tests.

    A coverage rate close to 100% eliminates most of the erratic behavior that a non-rigorously tested application can produce.

    However, a coverage rate of 100% does not guarantee that the program rigorously follows the standard, but that its behavior is most often in line with what the developer expected when he designed it.

  • Facilitated development

    The code is fully documented to facilitate maintenance and enhancements.

⚙ Setup

Installation

All operating systems should be supported, although this project is mainly developed for a GNU-Linux system as an everyday computer.

Simple installation from PyPI (beware, the package name is not the project name!):

$ pip install pyscape

Installation from sources :

$ pip install .

Install the project in editable mode for developpers :

$ make install
# Or
$ pip install -e .[dev]

Installation on Debian :

apt install ./escapy_1.0.0-2_all.deb

Usage

$ escapy -h
usage: [-h] [--pins [PINS]] [--single_sheets | --no-single_sheets] [-o [OUTPUT]]
[-c [CONFIG]] [-db [USERDEF_DB_FILEPATH]] [-v]
esc_prn
positional arguments:
esc_prn ESC raw printer file. - to read from stdin.
options:
-h, --help show this help message and exit
--pins [PINS] number of needles of the print head (9, 24, 48). Leave it unsetfor ESCP2 modern printers. (default: unset)
--single_sheets, --no-single_sheets
single-sheets or continuous paper. (default: single-sheets)
-o [OUTPUT], --output [OUTPUT]
PDF output file. - to write on stdout. (default: output.pdf)
-c [CONFIG], --config [CONFIG]
configuration file to use. (default: ./escapy.conf,
~/.local/share/escapy/escapy.conf)
-db [USERDEF_DB_FILEPATH], --userdef_db_filepath [USERDEF_DB_FILEPATH]
mappings between user-defined chararacter codes and unicode.
(default: ./user_defined_mapping.json)
-v, --version show program's version number and exit

NB : The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

Examples

Standard input/output streams are active, so it is possible to chain tools :

$ cat my_file.prn | escapy - -o - > my_pdf.pdf

For example, to convert the generated PDF into a TIFF image with GhostScript :

$ cat my_file.prn | escapy - -o - | \
gs -dBATCH -dNOPAUSE -dSAFER \
-dNoSeparationFiles -dSimulateOverprint=true -sDEVICE=tiffsep -r720 \
-sOutputFile=out-%d.tiff -

📰 Configuration file

The configuration file supplied by the application contains all the information needed to configure the virtual printer (margins, page formats, etc.), fonts and folders.

By default, the escapy.conf file is searched for in the current folder. If it doesn't exist, it is searched for in the standard software configuration folder on your system (see below). This folder is created if it doesn't already exist.

On GNU/Linux systems: ~/.local/share/escapy/, /etc/escapy/escapy.conf

On Windows systems: C:\\Users\\<YOUR_USERNAME>\\AppData\\Local\\escapy

On MacOS systems: /Users/<YOUR_USERNAME>/Library/Application Support/escapy

The default file is in the repository folder: data.

📰 Printer profiles

Profile example:

[colors]
0 = black
[color:black]
display = Black
offset = 120
rgb = #000000
cmyk = 0,0,0,100
[color:black:mono]
offset = 0

Profiles are files stored by default in a profiles folder next to the default configuration file installed on the system (see above).

They contain a section listing the colors used by the printer, as well as a section defining each of these colors as follows.

Expected keys in each color section:

  • rgb: RGB color code (starting with a #);
  • cmyk: CMYK channels (4 coma separated values).

Optional keys:

  • display: Human readable name;
  • offset: Nozzle position adjustement offset (in 1/180th of an inch).

Regarding nozzle offsets:
Most Epson print heads align all color nozzles on the same horizontal line. However, some models use one color as a reference, with the other color nozzles physically offset from it.

We need to compensate for the data generated by the driver in order to determine the correct position of the received colored data.

Depending on whether monochrome or color mode is selected, the range of nozzles may vary. That's why each color can be found in a dedicated monochrome version.

🔤 Fonts

For reasons of licensing and personal preference, EscaPy does not embed fonts (except for a minimal version of Courier and Helvetica).

List of fonts that can be embedded in Epson printers
  • Roman
  • Sans serif
  • Courier
  • Prestige
  • Script
  • OCR-B
  • OCR-A
  • Orator
  • Orator-S
  • Script C

Free fonts a proprietary equivalents :

ProprietaryFree ->
Courier NewLiberation MonoNoto Sans MonoFreeMonoFira Mono, Fira CodeRoboto Mono
Times New RomanLiberation SerifNoto SerifFreeSerifFiraGORoboto Serif
ArialLiberation SansNoto SansFreeSansFira SansRoboto
OCR-A / OCR-B fontsSquare
stroke ends OCR-A & OCR-B
Rounded ends & extended character coverage OCR-B

See also Recursive free font :

Free bitmap-style fonts :

Non-free fonts or fonts with restrictive licenses, often with a very limited character set, but close to the embedded fonts on Epson printers :


Noto, FreeFont and Fira fonts are normally installed on most systems, but can also be installed manually with the following command (on Debian systems and derivatives):

$ apt install fonts-noto fonts-freefont-ttf fonts-firacode

The same goes for Liberation fonts:

$ apt install fonts-liberation

Windows proprietary fonts can be installed with the following command:

$ apt install ttf-mscorefonts-installer

More generally, think of the fnt tool as a package manager for managing and installing fonts.

🅰️ User-defined characters

A JSON file is created and updated when custom characters are found. The user must specify the desired character in the unicode character set. The changes will be applied to the PDF by restarting the software.

Example:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "\ufffd"
}
}

Here, a character is defined under the unique key 83e1a70_1; the character with code 1 in the table is momentarily associated with the undefined character \ufffd (UNDEFINED).

A modification to match this code with the character could be as follows:

{
"83e1a70_1": {
"mode": 1,
"proportional_spacing": false,
"scripting": null,
"1": "♫"
}
}

By default, the JSON file (user_defined_mapping.json) is created in the current folder, but this can be changed in the configuration file. A folder containing the image of the bitmap character received can also be created by enabling the option images_path in the section [UserDefinedCharacters] of the configuration file.

🈳 Unsupported encodings (Chinese, Japanese, etc.)

The ESC/P and ESC/P2 standards do not seem to support Chinese or Japanese languages (encodings were apparently not provided for). However, some language evolutions (ESC/POS, ESC/P-K, ESC/P J84) and printers do support this. While in theory these languages can be implemented, their documentation remains hard to find and is beyond the scope of the current project. See Wikipedia - ESC variants.

The easiest way to achieve this is to use the printer in graphics mode (raster or bitimage) instead of text mode.

🏆 Acknowledgements

  • The management of modern fonts and their display on our screens would not have been possible without the work of French engineer Pierre Bézier (1910-1999), who also, through his work at Renault, revolutionized computer-aided design (CAD).

  • The Epson-Seiko teams of the 90's deserve our thanks for producing complete documentation of the language interpreted by their printers.

Absence of acknowledgements

Since the 2010s, Epson-Seiko (like so many other brands) tends to no longer publish language evolutions or advanced technical specifications for their machines. The brand tends to consider that this is now an industrial secret and none of your business.

In an ethical world, we wouldn't have to decipher these proprietary protocols. If you too feel that this is not appropriate, then you should consider manufacturers who respect your right to repair/modify what you own.

👏🏻 Contributions

This project is open for any contribution! Any bug report can be posted by opening an issue.

📖 License

EscaPy is distributed under two licenses: one for community use and the other for commercial use.

Community = Free and Open Source

EscaPy is released under the AGPL (Affero General Public License).

Commercial

The aim is to limit the uses integrated into proprietary devices whose vendors do not participate in the project in an equitable way, and who are guilty of any violation of the EscaPy license or of the free software used by EscaPy itself.

If you are interested in this license, please contact us.

Top ⬆️


Built with ❤️ with Document My Project

About

An advanced Python interpreter for ESC/P and ESC/P2 commands, efficiently and accurately converting your print workflows into precise vectorial PDFs.

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages