2015-08-03 156 views
2

我有一个爱普生热敏打印机,现在我要打印一些足够长的收据,我使用爱普生提供的代码示例。下面的一些代码,现在的问题是,当打印机超过一定长度(约30厘米)时,打印机将停止并切割收据,如下图所示。如何在不自动切割的情况下打印长期收据。C#打印收据长与爱普生热敏打印机

// Constant variable holding the printer name. 
    private const string PRINTER_NAME = "PosPrinter"; 

    // Variables/Objects. 
    private StatusAPI m_objAPI; 

    /// <summary> 
    /// The main entry point for the application. 
    /// </summary> 
    [STAThread] 
    static void Main() 
    { 
     Application.Run(new Form1()); 
    } 

    // The executed function when the Print button is clicked. 
    private void cmdPrint_Click(object sender, System.EventArgs e) 
    { 
     Boolean isFinish; 
     PrintDocument pdPrint = new PrintDocument(); 
     pdPrint.PrintPage += new PrintPageEventHandler(pdPrint_PrintPage); 
     // Change the printer to the indicated printer. 
     pdPrint.PrinterSettings.PrinterName = PRINTER_NAME; 

     try 
     { 
      // Open a printer status monitor for the selected printer. 
      if (m_objAPI.OpenMonPrinter(OpenType.TYPE_PRINTER, pdPrint.PrinterSettings.PrinterName) == ErrorCode.SUCCESS) 
      { 
       if (pdPrint.PrinterSettings.IsValid) 
       { 
        pdPrint.DocumentName = "Testing"; 
        // Start printing. 
        pdPrint.Print(); 

        // Check printing status. 
        isFinish = false; 

        // Perform the status check as long as the status is not ASB_PRINT_SUCCESS. 
        do 
        { 
         if (m_objAPI.Status.ToString().Contains(ASB.ASB_PRINT_SUCCESS.ToString())) 
          isFinish = true; 

        } while (!isFinish); 

        // Notify printing completion. 
        MessageBox.Show("Printing complete.", "Program06", MessageBoxButtons.OK, MessageBoxIcon.Information); 
       } 
       else 
        MessageBox.Show("Printer is not available.", "Program06", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 

       // Always close the Status Monitor after using the Status API. 
       if(m_objAPI.CloseMonPrinter() != ErrorCode.SUCCESS) 
        MessageBox.Show("Failed to close printer status monitor.", "Program06", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 

      } 
      else 
       MessageBox.Show("Failed to open printer status monitor.", "Program06", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
     } 
     catch 
     { 
      MessageBox.Show("Failed to open StatusAPI.", "Program06", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
     } 

    } 

    // The event handler function when pdPrint.Print is called. 
    // This is where the actual printing of sample data to the printer. 
    private void pdPrint_PrintPage(object sender, PrintPageEventArgs e) 
    { 
     float x, y, lineOffset; 

     // Instantiate font objects used in printing. 
     Font printFont = new Font("Microsoft Sans Serif", (float)10, FontStyle.Regular, GraphicsUnit.Point); // Substituted to FontA Font 

     e.Graphics.PageUnit = GraphicsUnit.Point; 

     // Draw the bitmap 
     x = 79; 
     y = 0; 
     e.Graphics.DrawImage(pbImage.Image, x, y, pbImage.Image.Width - 13, pbImage.Image.Height - 10); 

     // Print the receipt text 
     lineOffset = printFont.GetHeight(e.Graphics) - (float)3.5; 
     x = 10; 
     y = 24 + lineOffset; 
     for (int i = 0; i < 500; i++) 
     { 
      e.Graphics.DrawString("123xxstreet,xxxcity,xxxxstate", printFont, Brushes.Black, x, y); 
      y += lineOffset; 
     } 

     e.Graphics.DrawString("    TEL 9999-99-9999  C#2", printFont, Brushes.Black, x, y); 
     y += lineOffset; 
     e.Graphics.DrawString("  November.23, 2007  PM 4:24", printFont, Brushes.Black, x, y); 
     y = y + (lineOffset * (float)2.5) ; 
     e.Graphics.DrawString("apples      $20.00", printFont, Brushes.Black, x, y); 
     y += lineOffset; 
     e.Graphics.DrawString("grapes      $30.00", printFont, Brushes.Black, x, y); 
     y += lineOffset; 
     e.Graphics.DrawString("bananas      $40.00", printFont, Brushes.Black, x, y); 
     y += lineOffset; 
     e.Graphics.DrawString("lemons      $50.00", printFont, Brushes.Black, x, y); 
     y += lineOffset; 
     e.Graphics.DrawString("oranges      $60.00", printFont, Brushes.Black, x, y); 
     y += (lineOffset * (float)2.3); 
     e.Graphics.DrawString("Tax excluded.    $200.00", printFont, Brushes.Black, x, y); 
     y += lineOffset; 
     e.Graphics.DrawString("Tax  5.0%     $10.00", printFont, Brushes.Black, x, y); 
     y += lineOffset; 
     e.Graphics.DrawString("___________________________________", printFont, Brushes.Black, x, y); 

     printFont = new Font("Microsoft Sans Serif", 20, FontStyle.Regular, GraphicsUnit.Point); 
     lineOffset = printFont.GetHeight(e.Graphics) - 3; 
     y += lineOffset; 
     e.Graphics.DrawString("Total  $210.00", printFont, Brushes.Black, x - 1, y); 

     printFont = new Font("Microsoft Sans Serif", (float)10, FontStyle.Regular, GraphicsUnit.Point); 
     lineOffset = printFont.GetHeight(e.Graphics); 
     y = y + lineOffset + 1; 
     e.Graphics.DrawString("Customer's payment   $250.00", printFont, Brushes.Black, x, y); 
     y += lineOffset; 
     e.Graphics.DrawString("Change      $40.00", printFont, Brushes.Black, x, y - 2); 

     // Indicate that no more data to print, and the Print Document can now send the print data to the spooler. 
     e.HasMorePages = false; 
    } 

    // The executed function when the Close button is clicked. 
    private void cmdClose_Click(object sender, System.EventArgs e) 
    { 
     Close(); 
    } 

enter image description here

+0

你有没有找到这个解决方案? – Markinson

回答

2

大多数热敏打印机具有指示是否削减收到的设置。

在这种情况下,如果您绘制的内容超出默认边距(e.MarginBounds),您至少可以尝试将e.HasMorePages设置为true。 它取决于打印机驱动程序,如果它将在所有页面的末尾切割,或仅在最后一页切割。 当然你需要做你自己的分页,例如在第一页上只绘制应该在第一页上的项目等等。

-1

以下信息从Epson programming guide萃取。请参阅它的更多细节。

可以发出“部分切割”命令,可以通过它的十六进制代码调用,即port.write("\x1B\x69");

+0

虽然此链接可能回答问题,但最好在此处包含答案的基本部分,并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 - [来自评论](/ review/low-quality-posts/18938917) –

相关问题