CODING:
<?php
require_once '../../classes/PDO_connection.php';
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
//selecting items
$stmt = $pdo->prepare("SELECT variety, price, commision FROM nontextile_purchase_retailsales_wholesales WHERE bill_number = '$bill_no' AND commision != ''"); $stmt->execute();
$commisions = $stmt->fetchAll();
$stmt = $pdo->prepare("SELECT sum(commision) as commision_total FROM nontextile_purchase_retailsales_wholesales WHERE bill_number = '$bill_no'"); $stmt->execute();
$commision_totals = $stmt->fetchAll();
foreach($commision_totals as $commision_total){
$commision_total = $commision_total['commision_total'];
}
$nRows = $pdo->query("SELECT count(*) FROM nontextile_purchase_retailsales_wholesales WHERE bill_number = '$bill_no' AND commision != ''")->fetchColumn();
$stmt = $pdo->prepare("SELECT variety, quantity, price, total FROM nontextile_purchase_retailsales_wholesales WHERE bill_number = '$bill_no'"); $stmt->execute();
$columnWidths = array(
"variety"=>30,
"price"=>10,
"quantity"=>10,
"total"=>15
);
$handle = printer_open("TVS MSP 250 Star 1");
if($handle)
{
printer_start_doc($handle, "VI BILLING");
printer_start_page($handle);
printer_set_option($handle,PRINTER_PAPER_FORMAT,PRINTER_FORMAT_CUSTOM);
printer_set_option($handle,PRINTER_PAPER_LENGTH,153);
printer_set_option($handle,PRINTER_PAPER_WIDTH,254);
// Set print mode to RAW and send PDF to printer
printer_set_option($handle, PRINTER_MODE, "RAW");
printer_write($handle, "\t\t\t PADIYUR SARVODAYA SANGH ");
printer_write($handle, "\n");
printer_write($handle, "TIN: 33613080088 \t KHADI GRAMODYOG BHAVAN \t STD: 04257 245317");
printer_write($handle, "\n");
printer_write($handle, "\t\t\t SILK SHOWROOM A/C, PADIYUR");
printer_write($handle, "\n");
printer_write($handle, "---------------------------------------------------------------------------\n");
$customer_name = str_pad($ccustomer_name, 20, " ", STR_PAD_RIGHT);
$mobile = str_pad($mobile, 15, " ", STR_PAD_RIGHT);
$address = str_pad($address, 41, " ", STR_PAD_RIGHT);
printer_write($handle, "NAME: ".$customer_name." "."MOB :".$mobile."BILL NO: ".$bill_no);
printer_write($handle, "\n");
printer_write($handle, "ADDR: ".$address." DATE: ".$sale_date_original);
printer_write($handle, "\n");
printer_write($handle, "---------------------------------------------------------------------------\n");
printer_write($handle, "ITEM ");
printer_write($handle, "PRICE ");
printer_write($handle, "QUANTITY ");
printer_write($handle, "TOTAL \n");
printer_write($handle, "---------------------------------------------------------------------------\n");
while($showData = $stmt->fetch(PDO::FETCH_ASSOC)){
foreach($showData as $k=>$v){
if($k == 'price' || $k == 'total'){
$showData[$k] = str_pad(substr($showData[$k], 0, $columnWidths[$k]), $columnWidths[$k], " ", STR_PAD_LEFT);
}elseif($k == 'quantity'){
$showData[$k] = str_pad(substr($showData[$k], 0, $columnWidths[$k]), $columnWidths[$k], " ", STR_PAD_BOTH);
}else{
$showData[$k] = str_pad(substr($showData[$k], 0, $columnWidths[$k]), $columnWidths[$k], " ", STR_PAD_RIGHT);
}
}
$variety = $showData['variety'];
$quantity = $showData['quantity'];
$price = $showData['price'];
$total = $showData['total'];
printer_write($handle, $variety."".$price."".$quantity."".$total."\n");
}
//If Commision is there
if($nRows > 0){
$grand_total = str_pad($grand_total, 10, " ", STR_PAD_LEFT);
$quantitytotal = str_pad($quantitytotal, 10, " ", STR_PAD_BOTH);
printer_write($handle, " -------------------------------\n");
printer_write($handle, " GRAND TOTAL".$quantitytotal."".$grand_total);
printer_write($handle, "\n");
printer_write($handle, " COMMISION");
printer_write($handle, "\n");
foreach($commisions as $commisione){
$commision_amount = str_pad($commisione['commision'], 10, " ", STR_PAD_LEFT);
$commision_variety = str_pad($commisione['variety'], 30, " ", STR_PAD_LEFT);
printer_write($handle, " ".$commision_variety." : ". $commision_amount);
printer_write($handle, "\n");
}
$commision_total = str_pad($commision_total, 10, " ", STR_PAD_LEFT);
printer_write($handle, " ".number_format($commision_total, 2, '.', ''));
printer_write($handle, "\n");
}
$final_amount = str_pad($final_amount, 10, " ", STR_PAD_LEFT);
printer_write($handle, " -----------------------\n");
if($khadi_loan > 0){
$khadi_loan = str_pad($khadi_loan, 10, " ", STR_PAD_LEFT);
printer_write($handle, " VI LOAN: ".$khadi_loan);
printer_write($handle, "\n");
}
if($nRows > 0){
printer_write($handle, " NET AMOUNT: ".$final_amount);
}else{
$quantitytotal = str_pad($quantitytotal, 10, " ", STR_PAD_BOTH);
printer_write($handle, " TOTAL QTY :".$quantitytotal." "."NET AMOUNT: ".$final_amount);
}
printer_write($handle, "\n");
printer_write($handle, "---------------------------------------------------------------------------\n");
printer_write($handle, "\n");
printer_write($handle, "\n");
printer_write($handle, " MANAGER\n");
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
}
else "Couldn't connect...";
?>
问题: 上面的代码将原始数据发送到打印机并打印正常.. 我有问题
printer_start_page($handle);
printer_end_page($handle);
printer_end_doc($handle);
不知道如何使用上述命令,
上面的代码打印printer_write($ handle,“\ t \ t \ t PADIYUR SARVODAYA SANGH”);这一行然后进入新页面,然后开始打印其他行。
帮我解决这个问题
答案 0 :(得分:0)
您需要“开始”文档,然后在需要时创建新页面(不要忘记“结束”它。),然后结束文档。
printer_start_doc($handle, "Document name");
printer_start_page($handle); // Start page 1
// here goes the content of page 1 via printer_write
printer_end_page($handle); // Close page 1
printer_start_page($handle); // Start page 2
// here goes the content of page 2 via printer_write
printer_end_page($handle); // Close page 2
printer_end_doc($handle);