Estoy intentando imprimir un ticket en una impresora termica, cuando es menos de una hoja el contenido del ticket sale bien, pero cuando el contenido es muy extenso corta en una hoja y el contenido adicional no se imprime.
Tengo estas variables globales
private ArrayList headerLines = new ArrayList();
private ArrayList subHeaderLines = new ArrayList();
private ArrayList items = new ArrayList();
private ArrayList totales = new ArrayList();
private ArrayList footerLines = new ArrayList();
private int maxChar = 40;
private int maxCharDescription = 15;
private float topMargin = 3f;
private string fontName = "Lucida Console";
private int fontSize = 8;
private SolidBrush myBrush = new SolidBrush(Color.Black);
private Image headerImage;
private int count;
private int imageHeight;
private float leftMargin;
private Font printFont;
private Graphics gfx;
private string line;
Tengo un método para cada contenido del ticket.
private void DrawHeader()
{
foreach (string headerLine in this.headerLines)
{
if (headerLine.Length > this.maxChar)
{
int startIndex = 0;
for (int length = headerLine.Length; length > this.maxChar; length -= this.maxChar)
{
this.line = headerLine.Substring(startIndex, this.maxChar);
this.gfx.DrawString(this.line, this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
++this.count;
startIndex += this.maxChar;
}
this.line = headerLine;
this.gfx.DrawString(this.line.Substring(startIndex, this.line.Length - startIndex), this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
++this.count;
}
else
{
this.line = headerLine;
this.gfx.DrawString(this.line, this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
++this.count;
}
}
}
private void DrawSubHeader()
{
foreach (string subHeaderLine in this.subHeaderLines)
{
if (subHeaderLine.Length > this.maxChar)
{
int startIndex = 0;
for (int length = subHeaderLine.Length; length > this.maxChar; length -= this.maxChar)
{
this.line = subHeaderLine;
this.gfx.DrawString(this.line.Substring(startIndex, this.maxChar), this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
++this.count;
startIndex += this.maxChar;
}
this.line = subHeaderLine;
this.gfx.DrawString(this.line.Substring(startIndex, this.line.Length - startIndex), this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
++this.count;
}
else
{
this.line = subHeaderLine;
this.gfx.DrawString(this.line, this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
++this.count;
this.line = this.DottedLine();
this.gfx.DrawString(this.line, this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
++this.count;
}
}
this.DrawEspacio();
}
private void DrawItems()
{
OrderItem orderItem1 = new OrderItem('?');
this.gfx.DrawString("CANT DESCRIPCION PRECIO TOTAL", this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
++this.count;
this.DrawEspacio();
foreach (string orderItem2 in this.items)
{
this.line = orderItem1.GetItemCantidad(orderItem2);
this.gfx.DrawString(this.line, this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
this.line = orderItem1.GetItemTotal(orderItem2);
this.line = this.AlignRightText(this.line.Length) + this.line;
this.gfx.DrawString(this.line, this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
this.line = orderItem1.GetItemPrice(orderItem2);
this.gfx.DrawString(" " + this.line, this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
string itemName = orderItem1.GetItemName(orderItem2);
this.leftMargin = 0.0f;
if (itemName.Length > this.maxCharDescription)
{
int startIndex = 0;
for (int length = itemName.Length; length > this.maxCharDescription; length -= this.maxCharDescription)
{
this.line = orderItem1.GetItemName(orderItem2);
this.gfx.DrawString(" " + this.line.Substring(startIndex, this.maxCharDescription), this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
++this.count;
startIndex += this.maxCharDescription;
}
this.line = orderItem1.GetItemName(orderItem2);
this.gfx.DrawString(" " + this.line.Substring(startIndex, this.line.Length - startIndex), this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
++this.count;
}
else
{
this.gfx.DrawString(" " + orderItem1.GetItemName(orderItem2), this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
++this.count;
}
}
this.leftMargin = 0.0f;
this.DrawEspacio();
this.line = this.DottedLine();
this.gfx.DrawString(this.line, this.printFont, (Brush)this.myBrush, this.leftMargin, this.YPosition(), new StringFormat());
++this.count;
this.DrawEspacio();
}
En el evento PrintPage tengo lo siguiente:
private void pr_PrintPage(object sender, PrintPageEventArgs e)
{
this.gfx = e.Graphics;
this.DrawHeader();
this.DrawSubHeader();
this.DrawItems();
}
Y finalmente tengo un método que invoca la impresión
public void PrintTicket(string impresora)
{
this.printFont = new Font(this.fontName, (float)this.fontSize, FontStyle.Regular);
PrintDocument printDocument = new PrintDocument();
printDocument.PrinterSettings.PrinterName = impresora;
printDocument.PrintPage += new PrintPageEventHandler(this.pr_PrintPage);
printDocument.Print();
}
El problema es que cuando los item son muchos no sale todo lo que se agregó para imprimir.
Espero que puedan ayudarme.