to bigfox
  那招不行的,打印机最小的纸长是12.7mm,

解决方案 »

  1.   

    就是想一行一行的打字符串?我不太明白。你看这个类,可以一行行打。
    unit URaw; 

    Unit to print raw text 
    Author: Alejandro Castro 
    Date 16/Jul/2000 
    } interface uses SysUtils, Windows, WinSpool; type 
      TRawPrint = class(TObject)   private 
        xIsOpen: Boolean; 
        xHandle: THandle; 
        xBytesWritten: DWord; 
        xDocInfo: TDocInfo1; 
        xIsMatrix: Boolean;  // is a matrix printer ? 
        function ReadLasPrt: Boolean; 
        procedure WriteLasPrt(const Value : Boolean); 
        function ReadMatPrt: Boolean; 
        procedure WriteMatPrt(const Value : Boolean);   public 
        Row: Integer; // current row 
        Column: Integer; // current column 
        RowsPage: Integer; // no. of rows per page 
        Document: String; // name of the document for winspool 
        PrinterName: String; // name of the raw printer 
        Condensed: Boolean;  // print on condensed mode 
        SeqCondensed: String;  // sequence of chars for print to 16 cpi 
        SeqNormal: String;  // sequence of chars for print to 10 cpi     constructor Create; 
        function Open: Boolean; // open the printer 
        function Close: Boolean; // close the printer 
        Function InitPrinter: Boolean; 
        Function Write(xText: String): Boolean; 
        Procedure SetPos(xRow, xCol: Integer); 
        Procedure Go(xRow, xCol: Integer); // force to move the head of the printer 
        Procedure GoTop; // go to the begining of the next page or form 
        Procedure NewPage; // form feed 
        Procedure Print(xRow, xCol: Integer; xText: String); // print xText on the row, col 
        property MatrixPrinter: Boolean read ReadMatPrt write WriteMatPrt; 
        property LaserPrinter: Boolean read ReadLasPrt write WriteLasPrt; end; 
    implementation constructor TRawPrint.Create; 
    begin 
      Row:=0; 
      Column:=0; 
      RowsPage:=66; 
      xIsOpen:=False; 
      Condensed:=False; 
      Document:='Alfra'; 
      PrinterName:=''; 
      MatrixPrinter:=True; end; 
    function TRawPrint.ReadMatPrt : Boolean; 
    begin 
      Result:=xIsMatrix; 
    end; 
    procedure TRawPrint.WriteMatPrt(const Value : Boolean); 
    begin 
      xIsMatrix:=Value; 
      SeqNormal:=#18; 
      SeqCondensed:=#15; 
    end; 
    procedure TRawPrint.WriteLasPrt(const Value : Boolean); 
    begin 
      xIsMatrix:=not Value; 
      SeqNormal:=#27+'&l6D'+#27+'(s0p10H'; 
      SeqCondensed:=#27+'&l6D'+#27+'(s0p16.66H'; 
    end; function TRawPrint.ReadLasPrt : Boolean; 
    begin 
      Result:=not xIsMatrix; 
    end; 
    function TRawPrint.Open: Boolean; 
    begin 
      Result:=False; 
      if not xIsOpen then begin 
        if PrinterName<>'' then begin 
          if Document='' then 
            Document:='Alfra';       with xDocInfo do begin 
            pDocName := PChar(Document); 
            pOutputFile := nil; 
            pDatatype := 'RAW'; 
          end; 
          Result:=OpenPrinter(PChar(PrinterName), xHandle, nil); 
          if Result then begin 
            Row:=0; 
            Column:=0; 
            if StartDocPrinter(xHandle, 1, @xDocInfo)=0 then Begin 
              Result:=False; 
              ClosePrinter(xHandle); 
            end; 
          end; 
        end; 
        xIsOpen:=Result; 
      end; 
    end; function TRawPrint.Close: Boolean; 
    begin 
      if xIsOpen then 
        Result:=ClosePrinter(xHandle); 
    end; Procedure TRawPrint.SetPos(xRow,xCol : Integer); 
    begin 
      Column:=xCol; 
      Row:=xRow; 
    end; Function TRawPrint.InitPrinter: Boolean; 
    begin 
      Column:=0; 
      Row:=0; 
      if Condensed then 
        Write(SeqCondensed+#13) 
      else 
        Write(SeqNormal+#13);   Result:=True; 
    end; Procedure TRawPrint.Go(xRow, xCol: Integer); 
    var i: Integer; 
    begin 
      if Row>xRow then 
        GoTop;   i:=Row; 
      while i    Write(#10); 
        inc(i); 
        Row:=i; 
      end;   if Column>xCol then begin 
        Write(#13); 
        Column:=0; 
      end;   i:=Column; 
      if i<>xCol then 
        Write( Format('%-*s',[xCol-Column,'']) );   Column:=xCol; 
    end; Procedure TRawPrint.GoTop; 
    begin 
      Go(RowsPage,0); 
      Column:=0; 
      Row:=0; 
    end; 
    Procedure TRawPrint.Print(xRow, xCol: Integer; xText: String); 
    begin 
      go(xRow,xCol); 
      if Write(xText) then 
        Column:=Column+xBytesWritten; 
    end; Procedure TRawPrint.NewPage; 
    begin 
      Write(#12+#13); 
      Column:=0; 
      Row:=0; 
    end; 
    function TRawPrint.Write(xText: String): Boolean; 
    var xBuffer: String; 
    begin 
      Result:=False; 
      xBuffer:=xText;   if xIsOpen then 
        Result:=WritePrinter(xHandle, @xBuffer[1], Length(xBuffer), xBytesWritten); 
    end; end. 
    调用代码:var xPrn: TRawPrint; 
    begin 
      xPrn:=TRawPrint.Create; 
      xPrn.PrinterName:='\\ibmserver\ hp laserjet 1100 ';\\你的打印机名称,这里的名字是我门的网络打印机 
      if xPrn.Open then begin  
        xPrn.Condensed:=True; // print to 16 cpi 
        xPrn.InitPrinter; 
        xPrn.Print(2,10,'My Text'); // I set the row, column and text to print 
        xPrn.LaserPrinter:=True; // I can do it with laser printers; 
        xPrn.Write ('Another Text'); // I dont need to specify the row and column 
        xPrn.NewPage;  // Form Feed 
        xPrn.Close: // I close the printer 
      end; 
      xPrn.Free; // release the instance 
    end; 
      

  2.   

    hehehe,不用那么复杂,直接向打印机发送:’打印数据’+换行回车指令就行了