How to print a very long Ticket using PrintDocument

1

I'm trying to print a ticket on a thermal printer, the information that the ticket must contain is enough so the ticket has a considerable length. I'm using a PrintDocument object to print the ticket, in the PrintPage event I use a Graphics object to write all the information. When printed the ticket appears correctly, the problem is that it is not printed completely. Is there a way to indicate the size of the print and so the ticket can be printed out completely?

PrintDocument printDocument = new PrintDocument();
        printDocument.PrinterSettings.PrinterName = impresora;            
        printDocument.PrintPage += new PrintPageEventHandler(this.pr_PrintPage);
        printDocument.Print();

This is the PrintPage event:

    private void pr_PrintPage(object sender, PrintPageEventArgs e)
    {
        e.Graphics.PageUnit = GraphicsUnit.Millimeter;            
        this.gfx = e.Graphics;
        this.DrawHeader();
        this.DrawItems();
        this.DrawTotales();
        this.DrawFooter();            
    }

for the "Draw" methods I am using the DrawString function of the Graphics object (gfx).

    
asked by Juan Alberto 10.05.2018 в 00:44
source

1 answer

1

You can specify the size of the page to print indicating the PaperSize in the property DefaultPageSettings of PrinterSettings in the following way:

int width = 100; //Indicar el ancho de la pàgina
int height = 100; //Indicar el alto de la pàgina

PrintDocument printDocument = new PrintDocument();
printDocument.PrinterSettings.PrinterName = impresora;
printDocument.PrinterSettings.DefaultPageSettings.PaperSize = new PaperSize("Nombre a poner a esta configuración", width, height);
printDocument.PrintPage += new PrintPageEventHandler(this.pr_PrintPage);
printDocument.Print();
    
answered by 10.05.2018 в 09:32