Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't stop printing [closed]

I use this device to print a barcode but printer doesn't stop printing, giving me empty tags until I shut it down. I found this question but specifying the Paper Size didn't help me.

The code I use:

PrintDocument document = new PrintDocument();
document.DefaultPageSettings.PaperSize =
    new PaperSize("Custom", Centimeters(7), Centimeters(5));
document.PrintPage += (s, a) =>
{
    a.Graphics.DrawString("*123456*",
                          BarcodeFont,
                          new SolidBrush(Color.Black),
                          new Point(0, 0));
}
document.Print();

Centimeters Method:

// Converts the unit "Hundredths of an inch" to centimeter.
int Centimeters(int centimeters)
{
    return (int)((centimeters * 100) / 2.54);
}

It prints the barcode to first tag correctly but it doesn't stop. Tags are 7x5 cm. and I set the paper size according to this, I have no idea what else I can do.

Edit: Setting HasMorePages to false didn't help and I know it's not because of the device I use: There are some other programs I currently use to print barcodes and they all work.

like image 247
Şafak Gür Avatar asked Mar 23 '12 17:03

Şafak Gür


1 Answers

Set the HasMorePages property of the eventArgs to false:

document.PrintPage += (s, a) =>
{
    a.Graphics.DrawString("*123456*",
                          BarcodeFont,
                          new SolidBrush(Color.Black),
                          new Point(0, 0));
    a.HasMorePages = false;
}
like image 123
D Stanley Avatar answered Sep 30 '22 05:09

D Stanley