5

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.

Community
  • 1
  • 1
Şafak Gür
  • 7,045
  • 5
  • 59
  • 96
  • Use the debugger. Set a breakpoint on the PrintPage lambda code *and* the Print() call. With significant odds that the Print() call breakpoint hits more than once. Look at the call stack to see how that happened. – Hans Passant Mar 24 '12 at 14:25
  • @Hans, nope, it hits only once. – Şafak Gür Mar 26 '12 at 08:06
  • Are you changing the print stock? (Most) Thermal printers need to be re calibrated before it will notice the label size has changed. (sManual_English.pdf p27) – charlesbridge Mar 26 '12 at 11:28
  • this question has been 8yr... but I desperately need to know the solution for this... hopefully Safak looking at this message... – EH Ong Aug 03 '20 at 10:16
  • Sorry @EHOng, this was on my first job and I came to an age where I can't even remember what I had for breakfast anymore. :) I don't have anything backed up from that era to refer to either. The only thing I remember about that application is that we actually shipped it, and it was printing ok (I know that doesn't help much - sorry again for not updating here on time). – Şafak Gür Aug 07 '20 at 09:46

1 Answers1

5

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;
}
D Stanley
  • 149,601
  • 11
  • 178
  • 240