doujunchi1238 2014-06-14 07:31
浏览 48

从PHP页面打印RAW,将纸张送入新页面

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, "
");
   printer_write($handle, "TIN: 33613080088 \t    KHADI GRAMODYOG BHAVAN \t STD: 04257 245317");
   printer_write($handle, "
");
   printer_write($handle, "\t\t\t SILK SHOWROOM A/C, PADIYUR");
   printer_write($handle, "
");
   printer_write($handle, "---------------------------------------------------------------------------
");

   $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, "
");
   printer_write($handle, "ADDR: ".$address." DATE:  ".$sale_date_original);
   printer_write($handle, "
");

   printer_write($handle, "---------------------------------------------------------------------------
");
   printer_write($handle, "ITEM                              ");
   printer_write($handle, "PRICE     ");
   printer_write($handle, "QUANTITY       ");
   printer_write($handle, "TOTAL     
");
   printer_write($handle, "---------------------------------------------------------------------------
");

    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."
");
    }

    //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, "                                  -------------------------------
");
    printer_write($handle, "                                  GRAND TOTAL".$quantitytotal."".$grand_total);
    printer_write($handle, "
");
    printer_write($handle, "         COMMISION");
    printer_write($handle, "
");
        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, "
");
        }
            $commision_total = str_pad($commision_total, 10, " ", STR_PAD_LEFT);
            printer_write($handle, "                                                          ".number_format($commision_total, 2, '.', ''));
            printer_write($handle, "
");
    }

    $final_amount = str_pad($final_amount, 10, " ", STR_PAD_LEFT);
   printer_write($handle, "                                            -----------------------
");
   if($khadi_loan > 0){
    $khadi_loan = str_pad($khadi_loan, 10, " ", STR_PAD_LEFT);
    printer_write($handle, "                                               VI LOAN: ".$khadi_loan);
    printer_write($handle, "
");
   }
   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, "
");
   printer_write($handle, "---------------------------------------------------------------------------
");
   printer_write($handle, "
");
   printer_write($handle, "
");
   printer_write($handle, "                                                           MANAGER
");

    printer_end_page($handle);
    printer_end_doc($handle);

    printer_close($handle);

    }

    else "Couldn't connect...";
?>

QUESTION: The above code send raw data to printer and prints fine.. Im having problem with

    printer_start_page($handle);
printer_end_page($handle);
printer_end_doc($handle);

dont know how to use the above commands,

the above code prints printer_write($handle, "\t\t\t PADIYUR SARVODAYA SANGH "); this line then its going to the new page, then start printing other lines.

help me with this

  • 写回答

1条回答 默认 最新

  • doushaiyu5065 2014-06-14 07:35
    关注

    You need to 'start' the document, then create a new page whenever you need (don't forget to 'end' it.), then end the doc.

    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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)