IHunte
IHunte

Reputation: 21

ESC/POS Thermal Printer WD8260 - Fr Special Characters (é, è, à) Not Displaying Correctly in PHP

I'm working with a WD8260 thermal printer using PHP and the Mike42/escpos-php library. I'm having issues with French special characters not displaying correctly in the printed output.

Current setup:

Current code:

$connector = new FilePrintConnector("php://output");
$printer = new Printer($connector);

$printer->initialize();
$printer->selectCharacterTable(2); // PC850

$printer->text("Prénom: José\n");

$printer->cut();
$printer->close();

Output PrTénom: JosTé

$printer->getPrintConnector()->write("Pr" . chr(130) . "nom");

Upvotes: 2

Views: 52

Answers (1)

Sammitch
Sammitch

Reputation: 32272

The line:

$printer->selectCharacterTable(2); // PC850

implies that the printer is expecting data in the CP850 encoding, and given the garbled encoding it's probably getting UTF-8 instead.

Eg: The bytes for UTF-8 é are C2 82 which would render in CP850 as ┬é, and you've likely interpreted the printed box-drawing character as a T.

Using:

mb_convert_encoding($nom_str, "cp850", "UTF-8");

may fix this, however you need to definitively determine what the encoding of the source data is and put that in place of "UTF-8" if necessary.

It's important to note that, despite the existence of functions that claim to do so, string encoding cannot be reliably detected. It is metadata that must be explicitly known and tracked alongside the string data.

See also: UTF-8 all the way through

Upvotes: 2

Related Questions