
15/08/2007, 17:58
|
 | | | Fecha de Ingreso: septiembre-2004 Ubicación: Chapis Data Center
Mensajes: 27
Antigüedad: 20 años, 4 meses Puntos: 0 | |
Re: Problemas para imprimir un comprobante de pago en asp .NET Me parece que el crystal report lo dejare como muy ultima opcion, ya inverti mucho tiempo para que me imprima el ticket y la verdad no quiero invertir mas para aprender a usar el crystal report. Lo que necesito es enviarle la secuencia de escape a la impresora pero no se como. Tambien me dijeron que en el VB6 usar el metodo EndDocument; pero no eh encontrado nada parecido en .NET; solo encontre "EndPrint" del componente "PrintDocument" pero solo es un evento que informa que termino la impresion.
la clase que uso es esta(en C#):
Código:
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Collections;
namespace DataBase.Normay.ElArco.Source.DataBase.Venta
{
public class Ticket
{
ArrayList headerLines = new ArrayList();
ArrayList subHeaderLines = new ArrayList();
ArrayList items = new ArrayList();
ArrayList totales = new ArrayList();
ArrayList footerLines = new ArrayList();
private Image headerImage = null;
public void PrintTicket(string impresora)
{
printFont = new Font(fontName, fontSize, FontStyle.Regular);
PrintDocument pr = new PrintDocument();
pr.PrinterSettings.PrinterName = impresora;
pr.PrintPage += new PrintPageEventHandler(pr_PrintPage);
pr.Print();
}
private void pr_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.PageUnit = GraphicsUnit.Millimeter;
gfx = e.Graphics;
DrawImage();
DrawHeader();
DrawSubHeader();
// DrawItems();
DrawTotales();
DrawFooter();
if (headerImage != null)
{
HeaderImage.Dispose();
headerImage.Dispose();
}
}
private float YPosition()
{
return topMargin + (count * printFont.GetHeight(gfx) + imageHeight);
}
private void DrawImage()
{
if (headerImage != null)
{
try
{
gfx.DrawImage(headerImage, new Point((int)leftMargin, (int)YPosition()));
double height = ((double)headerImage.Height / 58) * 15;
imageHeight = (int)Math.Round(height) + 3;
}
catch (Exception)
{
}
}
}
private void DrawHeader()
{
foreach(string header in headerLines)
{
if (header.Length > maxChar)
{
int currentChar = 0;
int headerLenght = header.Length;
while (headerLenght > maxChar)
{
line = header.Substring(currentChar, maxChar);
gfx.DrawString(line, printFont, myBrush, leftMargin,YPosition(), new StringFormat());
count++;
currentChar += maxChar;
headerLenght -= maxChar;
}
line = header;
gfx.DrawString(line.Substring(currentChar, line.Length - currentChar), printFont, myBrush, leftMargin,YPosition(), new StringFormat());
count++;
}
else
{
line = header;
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition(), new StringFormat());
count++;
}
}
DrawEspacio();
}
private void DrawSubHeader()
{
foreach (string subHeader in subHeaderLines)
{
if (subHeader.Length > maxChar)
{
int currentChar = 0;
int subHeaderLenght = subHeader.Length;
while (subHeaderLenght > maxChar)
{
line = subHeader;
gfx.DrawString(line.Substring(currentChar, maxChar), printFont, myBrush, leftMargin,YPosition(), new StringFormat());
count++;
currentChar += maxChar;
subHeaderLenght -= maxChar;
}
line = subHeader;
gfx.DrawString(line.Substring(currentChar, line.Length - currentChar), printFont, myBrush, leftMargin, YPosition(), new StringFormat());
count++;
}
else
{
line = subHeader;
gfx.DrawString(line, printFont, myBrush, leftMargin,YPosition(), new StringFormat());
count++;
//line = DottedLine();
//gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition(), new StringFormat());
//count++;
}
}
DrawEspacio();
}
private void DrawFooter()
{
foreach (string footer in footerLines)
{
if (footer.Length > maxChar)
{
int currentChar = 0;
int footerLenght = footer.Length;
while (footerLenght > maxChar)
{
line = footer;
gfx.DrawString(line.Substring(currentChar, maxChar), printFont, myBrush, leftMargin, YPosition(), new StringFormat());
count++;
currentChar += maxChar;
footerLenght -= maxChar;
}
line = footer;
gfx.DrawString(line.Substring(currentChar, line.Length - currentChar), printFont, myBrush, leftMargin, YPosition(), new StringFormat());
count++;
}
else
{
line = footer;
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition(), new StringFormat());
count++;
}
}
leftMargin = 0;
DrawEspacio();
}
private void DrawEspacio()
{
line = "";
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition(), new StringFormat());
count++;
}
}
}
y para usarla utilizo estos metodos (en VB):
Código:
tiquete.AddHeaderLine(" ¡Comprobante de pago!")
tiquete.AddSubHeaderLine("Cliente: " & lblCliente.Text)
tiquete.AddFooterLine(" ¡ GRACIAS POR SU PAGO !")
tiquete.PrintTicket("Pruebas")
El problema es que no se ni como ni donde meter las secuencias de escape correspondientes a las del modelo de mi impresora (tengo un pdf donde detalla el codigo decimal y hexadecimal de cada funcionalidad de la impresora)
. |