2017-06-28 8 views
5

カスタムTG2480-Hプリンタを使用してレシートを印刷しています。私はロゴを除いて領収書をすべて持っています。カスタムTG2480Hプリンタにロゴを印刷する

私はロゴを表し、適切な次元を持っているモノクロの.bmpファイルを持っています。

私は、ファイルを取得異なる応答タイプを使用しています:

this.http.get('/assets/images/brand/logo-bnw.bmp', { 
    responseType: ResponseContentType.Blob 
}).subscribe((response: Response) => { 
    console.log('Blob bytes', this.kiowarePrintService.getBytesFromText(response.text())); 
}); 
this.http.get('/assets/images/brand/logo-bnw.bmp', { 
    responseType: ResponseContentType.Text 
}).subscribe((response: Response) => { 
    console.log('Text bytes', this.kiowarePrintService.getBytesFromText(response.text())); 
}); 
this.http.get('/assets/images/brand/logo-bnw.bmp', { 
    responseType: ResponseContentType.ArrayBuffer 
}).subscribe((response: Response) => { 
    console.log('ArrayBuffer bytes', this.kiowarePrintService.getBytesFromText(response.text())); 
}); 

ここResponseContentType上の文書とそれが持つことができる異なった値です。

これはgetBytesFromTextのコードです:バイトへの応答を変換する

getBytesFromText(text: string) { 
    const bytes: number[] = []; 
    for (let i = 0; i < text.length; i++) { 
     bytes.push(text.charCodeAt(i)); 
    } 
    return bytes; 
    } 

これらの値を出力します。これらのすべてが間違っているように見える

Blob bytes (2) [123, 125] 

Text bytes (951) [66, 77, 65533, 3, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 40, 0, 0, 0, 120, 0, 0, 0, 56, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 65533, 3, 0, 0, 65533, 14, 0, 0, 65533, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65533, 65533, 65533, 0, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 0, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 0, 65533, 65533, 65533, 65533, 65533, 65533…] 

ArrayBuffer bytes (479) [19778, 958, 0, 0, 0, 62, 0, 40, 0, 120, 0, 56, 0, 1, 1, 0, 0, 896, 0, 3780, 0, 3780, 0, 0, 0, 0, 0, 0, 0, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535…] 

、ブロブバイトの量があまりにも低く、他の2つは両方ともバイト(> 255)より大きい数字を含んでいます。

私はとにかくプリンタにこれらのバイトを送信しようとしたし、次のを思い付いてきました:

を印刷します

EDIT:広告を試しましたD 'content-type': 'image/bmp'ヘッダー:

const headers: Headers = new Headers({'Content-Type': 'image/bmp'}); 
    const options: RequestOptions = new RequestOptions({headers: headers}); 
    this.http.get('/assets/images/brand/logo-bnw.bmp', options).subscribe((response: Response) => { 
     console.log('image/bmp bytes', this.kiowarePrintService.getBytesFromText(response.text())); 
    }); 

ログこの:それのように見えます

image/bmp bytes (951) [66, 77, 65533, 3, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 40, 0, 0, 0, 120, 0, 0, 0, 56, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 65533, 3, 0, 0, 65533, 14, 0, 0, 65533, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65533, 65533, 65533, 0, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 0, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 0, 65533, 65533, 65533, 65533, 65533, 65533…] 

あなたは戻り値の型のすべてについてresponse.textを()を使用している

+0

あなたは「プリンタにこれらのバイトを送信する」しようとしていると言っています。どのような方法を使いましたか? window.print()を使用しましたか他のブラウザプラグインを作成しましたか? – wannadream

答えて

1

テキスト応答と同じです。バイナリデータの場合は、blobとして保存する必要があります。

response.arrayBuffer() 

これは、期待している正しいバイト配列を与えるはずです。

この質問にも関連している:Get Image or byte data with http

トップの答えはやってのアプローチを取ります。

var blob = new Blob([new Uint8Array(response._body)] 
関連する問題