I have an Epson thermal printer, and now I have to print some long enough receipt, I use the code sample provided by Epson. Some of the code as below, the problem now is that the printer will stop and cut the receipt when it exceed certain (around 30cm) length as photo shown below. How can I print long receipt without auto cut.
// 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();
}
Most thermal printers have a setting that indicates whether or not to cut the receipt.
In this case, you could at least try to set e.HasMorePages to true, if the content you draw is outside of the default margins (e.MarginBounds). It depends on the printer driver if it will cut at the end of all pages, or only at the last page. Of course you will need to do your own paging, e.g. on the first page only draw items that should be on the first page and so on.