我有一個愛普生熱敏打印機,現在我要打印一些足夠長的收據,我使用愛普生提供的代碼示例。下面的一些代碼,現在的問題是,當打印機超過一定長度(約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();
}
你有沒有找到這個解決方案? – Markinson