Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unknow unicode?? #356

Closed
sunry2ntkh opened this issue May 6, 2017 · 5 comments
Closed

unknow unicode?? #356

sunry2ntkh opened this issue May 6, 2017 · 5 comments

Comments

@sunry2ntkh
Copy link

18378800_772233969608454_1860775692_o

@sunry2ntkh
Copy link
Author

*/ header('Content-Type: text/html; charset=utf-8'); //mb_internal_encoding(); // // Lengths seem to be different on your computer // $str = "សសាសដថាdsfsd232"; // echo mb_strlen($str) . "\n"; // echo mb_strlen($str, 'UTF-8') . "\n"; // exit(); require __DIR__ . '/../autoload.php'; use Mike42\Escpos\Printer; //use Mike42\Escpos\PrintConnectors\FilePrintConnector; use Mike42\Escpos\PrintConnectors\WindowsPrintConnector; use Mike42\Escpos\EscposImage; $connector = new WindowsPrintConnector("smb://PC-01/80mm"); $printer = new Printer($connector); $str = base64_decode(" sdfasdf dafdដដដ"); // Epson character tables //$try = array( // 37 => 'CP864', // 50 => 'CP1256'); // E-pos TEP 200M character tables $try = array( // 28 => 'CP864', // 29 => 'CPW1001', 33 => 'CP720', 34 => 'CP1256' , // 63 => 'CP864', 34 => 'CP1256', // 7 => '0bbbbbbb', 82 => 'CP1001' ); foreach($try as $targetNumber => $targetEncoding) { $map = makeMap($targetEncoding); $outp = convert($str, $map); /* Print test output */ $printer -> selectCharacterTable($targetNumber); $printer -> text($targetNumber." : ".$targetEncoding. "\n"); if(count($map) == 0) { $printer -> text("Can't make $targetEncoding output with iconv.\n"); } else { $printer -> textRaw(strrev($outp) . "\n"); } compactCharTable($printer, 8); } $printer -> feed(2); $printer -> cut(); $printer -> close(); function convert($str, $map) { // Convert UTF8 to the target encoding $len = mb_strlen($str); $outp = str_repeat("?", $len); for($i = 0; $i < $len; $i++) { $utf8 = mb_substr($str, $i, 1); if(isset($map[$utf8])) { $outp[$i] = $map[$utf8]; } } return $outp; } function makeMap($targetEncoding) { // Make map of target encoding v UTF-8 $map = array(); for($i = 0; $i < 255; $i++) { $native = chr($i); $utf8 = @iconv($targetEncoding, 'UTF-8', $native); if($utf8 == '') { continue; } $map[$utf8] = $native; } return $map; } function compactCharTable($printer, $start = 2) { // Output a table of characters for a code $chars = str_repeat(' ', 256); for($i = 0; $i < 255; $i++) { $chars[$i] = ($i > 32 && $i != 127) ? chr($i) : ' '; } $printer -> setEmphasis(true); $printer -> textRaw(" 0123456789ABCDEF\n"); $printer -> setEmphasis(false); for($y = $start; $y < 16; $y++) { $printer -> setEmphasis(true); $printer -> textRaw(strtoupper(dechex($y)) . " "); $printer -> setEmphasis(false); $printer -> textRaw(substr($chars,$y * 16, 16) . "\n"); } }

@mdestafadilah
Copy link

What printer type?

@sunry2ntkh
Copy link
Author

SPRT printer

@sunry2ntkh
Copy link
Author

20170516_101959

@mike42
Copy link
Owner

mike42 commented May 20, 2017

I'll close this off as the character encodings for this printer wont allow it to print this natively until there is a profile for your printer. receipt-print-hq/escpos-printer-db#28 lists some things that you will need to know to make one.

@mike42 mike42 closed this as completed May 20, 2017
Repository owner locked and limited conversation to collaborators May 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants