В общем сделал так:
var encodeCP866 = function (str) {
var ep = {
'& #0;': { 'dec': '0'},
'& #1;': { 'dec': '1'},
'& #2;': { 'dec': '2'},
'& #3;': { 'dec': '3'},
'& #4;': { 'dec': '4'},
'& #5;': { 'dec': '5'},
'& #6;': { 'dec': '6'},
'& #7;': { 'dec': '7'},
'& #8;': { 'dec': '8'},
'% 09': { 'dec': '9'},
'& #10;': { 'dec': '10'},
'& #11;': { 'dec': '11'},
'& #12;': { 'dec': '12'},
'% 0A': { 'dec': '13'},
'& #14;': { 'dec': '14'},
'& #15;': { 'dec': '15'},
'& #16;': { 'dec': '16'},
'& #17;': { 'dec': '17'},
'& #18;': { 'dec': '18'},
'& #19;': { 'dec': '19'},
'& #20;': { 'dec': '20'},
'& #21;': { 'dec': '21'},
'& #22;': { 'dec': '22'},
'& #23;': { 'dec': '23'},
'& #24;': { 'dec': '24'},
'& #25;': { 'dec': '25'},
'& #26;': { 'dec': '26'},
'& #27;': { 'dec': '27'},
'& #28;': { 'dec': '28'},
'& #29;': { 'dec': '29'},
'& #30;': { 'dec': '30'},
'& #31;': { 'dec': '31'},
'& #32;': { 'dec': '32'},
"% 20": { "dec": "32"},
"!": { "dec": "33"},
"% 22": { "dec": "34"},
"#": { "dec": "35"},
"$": { "dec": "36"},
"% 25": { "dec": "37"},
"&": { "dec": "38"},
"'": { "dec": "39"},
"(": { "dec": "40"},
")": { "dec": "41"},
"*": { "dec": "42"},
"+": { "dec": "43"},
"{: { hex": "2C"},
"-": { "dec": "45"},
".": { "dec": "46"},
"/": { "dec": "47"},
"0": { "dec": "48"},
"1": { "dec": "49"},
"2": { "dec": "50"},
"3": { "dec": "51"},
"4": { "dec": "52"},
"5": { "dec": "53"},
"6": { "dec": "54"},
"7": { "dec": "55"},
"8": { "dec": "56"},
"9": { "dec": "57"},
":": { "dec": "58"},
";": { "dec": "59"},
"% 3C": { "dec": "60"},
"=": { "dec": "61"},
"% 3E": { "dec": "62"},
"?": { "dec": "63"},
"@": { "dec": "64"},
"A": { "dec": "65"},
"B": { "dec": "66"},
"C": { "dec": "67"},
"D": { "dec": "68"},
"E": { "dec": "69"},
"F": { "dec": "70"},
"G": { "dec": "71"},
"H": { "dec": "72"},
"I": { "dec": "73"},
"J": { "dec": "74"},
"K": { "dec": "75"},
"L": { "dec": "76"},
"M": { "dec": "77"},
"N": { "dec": "78"},
"O": { "dec": "79"},
"P": { "dec": "80"},
"Q": { "dec": "81"},
"R": { "dec": "82"},
"S": { "dec": "83"},
"T": { "dec": "84"},
"U": { "dec": "85"},
"V": { "dec": "86"},
"W": { "dec": "87"},
"X": { "dec": "88"},
"Y": { "dec": "89"},
"Z": { "dec": "90"},
"% 5B": { "dec": "91"},
"% 5C": { "dec": "92"},
"% 5D": { "dec": "93"},
"% 5E": { "dec": "94"},
"_": { "dec": "95"},
"% 60": { "dec": "96"},
"a": { "dec": "97"},
"b": { "dec": "98"},
"c": { "dec": "99"},
"d": { "dec": "100"},
"e": { "dec": "101"},
"f": { "dec": "102"},
"g": { "dec": "103"},
"h": { "dec": "104"},
"i": { "dec": "105"},
"j": { "dec": "106"},
"k": { "dec": "107"},
"l": { "dec": "108"},
"m": { "dec": "109"},
"n": { "dec": "110"},
"o": { "dec": "111"},
"p": { "dec": "112"},
"q": { "dec": "113"},
"r": { "dec": "114"},
"s": { "dec": "115"},
"t": { "dec": "116"},
"u": { "dec": "117"},
"v": { "dec": "118"},
"w": { "dec": "119"},
"x": { "dec": "120"},
"y": { "dec": "121"},
"z": { "dec": "122"},
"% 7B": { "dec": "123"},
"% 7C": { "dec": "124"},
"% 7D": { "dec": "125"},
"~": { "dec": "126"},
"% D0% 90": { "dec": "128"},
"% D0% 91": { "dec": "129"},
"% D0% 92": { "dec": "130"},
"% D0% 93": { "dec": "131"},
"% D0% 94": { "dec": "132"},
"% D0% 95": { "dec": "133"},
"% D0% 96": { "dec": "134"},
"% D0% 97": { "dec": "135"},
"% D0% 98": { "dec": "136"},
"% D0% 99": { "dec": "137"},
"% D0% 9A": { "dec": "138"},
"% D0% 9B": { "dec": "139"},
"% D0% 9C": { "dec": "140"},
"% D0% 9D": { "dec": "141"},
"% D0% 9E": { "dec": "142"},
"% D0% 9F": { "dec": "143"},
"% D0% A0": { "dec": "144"},
"% D0% A1": { "dec": "145"},
"% D0% A2": { "dec": "146"},
"% D0% A3": { "dec": "147"},
"% D0% A4": { "dec": "148"},
"% D0% A5": { "dec": "149"},
"% D0% A6": { "dec": "150"},
"% D0% A7": { "dec": "151"},
"% D0% A8": { "dec": "152"},
"% D0% A9": { "dec": "153"},
"% D0% AA": { "dec": "154"},
"% D0% AB": { "dec": "155"},
"% D0% AC": { "dec": "156"},
"% D0% AD": { "dec": "157"},
"% D0% AE": { "dec": "158"},
"% D0% AF": { "dec": "159"},
"% D0% B0": { "dec": "160"},
"% D0% B1": { "dec": "161"},
"% D0% B2": { "dec": "162"},
"% D0% B3": { "dec": "163"},
"% D0% B4": { "dec": "164"},
"% D0% B5": { "dec": "165"},
"% D0% B6": { "dec": "166"},
"% D0% B7": { "dec": "167"},
"% D0% B8": { "dec": "168"},
"% D0% B9": { "dec": "169"},
"% D0% BA": { "dec": "170"},
"% D0% BB": { "dec": "171"},
"% D0% BC": { "dec": "172"},
"% D0% BD": { "dec": "173"},
"% D0% BE": { "dec": "174"},
"% D0% BF": { "dec": "175"},
"% E2% 96% 91": { "dec": "176"},
"% E2% 96% 92": { "dec": "177"},
"% E2% 96% 93": { "dec": "178"},
"% E2% 94% 82": { "dec": "179"},
"% E2% 94% A4": { "dec": "180"},
"% E2% 95% A1": { "dec": "181"},
"% E2% 95% A2": { "dec": "182"},
"% E2% 95% 96": { "dec": "183"},
"% E2% 95% 95": { "dec": "184"},
"% E2% 95% A3": { "dec": "185"},
"% E2% 95% 91": { "dec": "186"},
"% E2% 95% 97": { "dec": "187"},
"% E2% 95% 9D": { "dec": "188"},
"% E2% 95% 9C": { "dec": "189"},
"% E2% 95% 9B": { "dec": "190"},
"% E2% 94% 90": { "dec": "191"},
"% E2% 94% 94": { "dec": "192"},
"% E2% 94% B4": { "dec": "193"},
"% E2% 94% AC": { "dec": "194"},
"% E2% 94% 9C": { "dec": "195"},
"% E2% 94% 80": { "dec": "196"},
"% E2% 94% BC": { "dec": "197"},
"% E2% 95% 9E": { "dec": "198"},
"% E2% 95% 9F": { "dec": "199"},
"% E2% 95% 9A": { "dec": "200"},
"% E2% 95% 94": { "dec": "201"},
"% E2% 95% A9": { "dec": "202"},
"% E2% 95% A6": { "dec": "203"},
"% E2% 95% A0": { "dec": "204"},
"% E2% 95% 90": { "dec": "205"},
"% E2% 95% AC": { "dec": "206"},
"% E2% 95% A7": { "dec": "207"},
"% E2% 95% A8": { "dec": "208"},
"% E2% 95% A4": { "dec": "209"},
"% E2% 95% A5": { "dec": "210"},
"% E2% 95% 99": { "dec": "211"},
"% E2% 95% 98": { "dec": "212"},
"% E2% 95% 92": { "dec": "213"},
"% E2% 95% 93": { "dec": "214"},
"% E2% 95% AB": { "dec": "215"},
"% E2% 95% AA": { "dec": "216"},
"% E2% 94% 98": { "dec": "217"},
"% E2% 94% 8C": { "dec": "218"},
"% E2% 96% 88": { "dec": "219"},
"% E2% 96% 84": { "dec": "220"},
"% E2% 96% 8C": { "dec": "221"},
"% E2% 96% 90": { "dec": "222"},
"% E2% 96% 80": { "dec": "223"},
"% D1% 80": { "dec": "224"},
"% D1% 81": { "dec": "225"},
"% D1% 82": { "dec": "226"},
"% D1% 83": { "dec": "227"},
"% D1% 84": { "dec": "228"},
"% D1% 85": { "dec": "229"},
"% D1% 86": { "dec": "230"},
"% D1% 87": { "dec": "231"},
"% D1% 88": { "dec": "232"},
"% D1% 89": { "dec": "233"},
"% D1% 8A": { "dec": "234"},
"% D1% 8B": { "dec": "235"},
"% D1% 8C": { "dec": "236"},
"% D1% 8D": { "dec": "237"},
"% D1% 8E": { "dec": "238"},
"% D1% 8F": { "dec": "239"},
"% D0% 81": { "dec": "240"},
"% D1% 91": { "dec": "241"},
"% D0% 84": { "dec": "242"},
"% D1% 94": { "dec": "243"},
"% D0% 87": { "dec": "244"},
"% D1% 97": { "dec": "245"},
"% D0% 8E": { "dec": "246"},
"% D1% 9E": { "dec": "247"},
"% C2% B0": { "dec": "248"},
"% E2% 88% 99": { "dec": "249"},
"% C2% B7": { "dec": "250"},
"% E2% 88% 9A": { "dec": "251"},
"% E2% 84% 96": { "dec": "252"},
"% C2% A4": { "dec": "253"},
"% E2% 96% A0": { "dec": "254"},
};
var byteArray =[];
for (var x = 0; x < str.length; x++) {
var l_key=encodeURI( str.substr(x, 1) ); //encoded key as
if (ep[l_key] === undefined) {
//неизвестный символ
byteArray.push(63);
byteArray = byteArray.concat(encodeCP866(l_key));
byteArray.push(63);
// debugger;
} else if (l_key == '%0A') {//обработка CRLF
byteArray.push(10);
byteArray.push(13);
}else {
byteArray.push(parseInt(ep[l_key].dec));//parseInt(hexdata.substr(x * 2, 2), 16);
}
}
var ret = new Uint8Array(byteArray);
return ret;
};
( !!! надо убрать пробелы после & и %)
Вызывать так:
saveAs(new Blob([encodeCP866("Привет, Вася!\nС днём рождения")], {type: "application/octet-stream"}),"testCP.p01")
Ну и до конца - на файл c расширением p01 вешается приложение - батничек в котором написано:
copy %1 prn
и - маппинг сетевого принтера на lpt1:
net use lpt1 \\computer1\epson