jueves, 18 de agosto de 2022

 

como imprimir comprobantes en c# (printDocument)

 hey hola, nuevamente yo por aquí ,para compartirles este articulo a como hacer la impresion de comprobantes de pago en c#












controles a utilizar son:


primeramente Diseñamos nuestro formulario como la imagen siguiente


Vamos a código.

primeramente creamos nuestro método impresión.

private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

 

{

            //Image image = panel1.BackgroundImage;

e.Graphics.DrawString("Tiket de ventas", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(30, 10));

e.Graphics.DrawString("_________________________________________", new Font("Arial", 6, FontStyle.Regular), Brushes.Black, new Point(3, 20));

 

e.Graphics.DrawString("nro: 100", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(5, 40));

e.Graphics.DrawString("fecha de venta : 18/08/2022", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(5, 60));

 

}

 
luego llamamos nuestro metodo desde nuestro buton Imprimir

private void button1_Click(object sender, EventArgs e)

        {

            //printDocument.Print();

            PrintDocument pd = new PrintDocument();

            //PaperSize ps = new PaperSize("factura", 827, 1169);

             PaperSize ps = new PaperSize("Boleta", 200, 600);

pd.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);

 

            pd.PrintController = new StandardPrintController();

            pd.DefaultPageSettings.Margins.Left = 0;

            pd.DefaultPageSettings.Margins.Right = 0;

            pd.DefaultPageSettings.Margins.Top = 0;

            pd.DefaultPageSettings.Margins.Bottom = 0;

 

            pd.DefaultPageSettings.PaperSize = ps;

            pd.Print();

        }

codigo para nuestro buton vista previa de impresion

 

private void button2_Click(object sender, EventArgs e)

        {

            printPreviewDialog1.Document = printDocument;

            printPreviewDialog1.ShowDialog();

        }

eso seria todo espero haber ayudado con este articulo.

gracias saludos.



Share: