0 レビュー
1 回答
ドラフトモードでのドットマトリックスプリンターへの印刷-PHP
請求書を生成するオプションを備えたPHPWebアプリケーションがあります。問題は、ドラフトモードでドットマトリックスプリンターを使用して請求書を印刷する必要があることです。試しましたが、通常のプリンターのように大きなフォントで印刷されます。単にページと同じ形式で印刷します。
領収書のように印刷する必要があります。 PHPで何かをフォーマットする必要がありますか?
わからない
0
レビュー
答え :
解決策:
まあ、rawモードで印刷する必要があると思います。
この問題を完全に解決したとは言いませんが、これが私の試みです。
まず、ドットマトリックスプリンタが接続されているシステム(おそらくポートLPT1)に「汎用/テキストのみ」のドライバが必要です。
次に、ESCPコマンドをプリンターに送信し、phpの組み込みプロセスを使用して印刷しないようにする必要があります。
たとえば、135 * 66文字の配列を作成できます。ここで、135は文字単位の通常のページ幅で、66は通常の印刷行数です(8-1 / 2 "xの24ピンドットマトリックスプリンターの場合)。 12 "用紙サイズ)。配列を文字列ではなく文字で埋めるように注意する必要があります。嘘をつく:
$GRAND_ARRAY = array();
$maxCharactersPerLine = 135;
$maxLines = 66;
//initialize the array with spaces and the last column of \r\n
for($i=0; $i<$maxLines; $i++){
$pos = $i*$maxCharactersPerLine + ($maxCharactersPerLine-1) + $i + 1;
$value = "\r\n";
$this->printChars($GRAND_ARRAY, $pos, $value);
}
//make an array that fits every one character of the page
//plus a column for the "next line" character
$totalCells = $maxCharactersPerLine * $maxLines + $maxLines - 1;
//what you want to print
$value = "name:"; //here is a string with 5 characters
//where you want to print it on the page
//$line = 2
//$column = 5
//consider that array starts at 0 and not 1
//$pos = ($column - 1) * $maxCharactersPerLine + $line + $column - 2;
$pos = 275; //position is 5th character in line 2
//do not just $GRAND_ARRAY[$pos] = $value because you should
//make sure that every array cell has only one character
$this->printChars($GRAND_ARRAY, $pos, $value, 1);
// also included a flag if you want to print only the $limit characters of $newstring
public function printChars(&$mainArray, $start, $newString, $limit=0){
$j = $start;
$charsArray = $this->mb_str_split($newString);
//$len = mb_strlen($newString, "UTF-8"); //can't remember why not this
$len = count($charsArray);
for($i=0; $i<$len; $i++){
if($limit > 0 && $limit < $i){
return;
}else{
$mainArray[$j] = $charsArray[$i];
$j = $j + 1;
}
}
}
//this I found here on s.o. i think.
public function mb_str_split( $string ) {
# Split at all position not after the start: ^
# and not before the end: $
return preg_split('/(?<!^)(?!$)/u', $string );
}
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。