0

When ever I print a image label to a zebra printer, the label prints normally and then an extra blank label is fed and this subsequently misaligns the top margin of each printed label afterwards.

I have looked online and at a lot of questions that have been already posted (i.e. printdocument adds blank page), with no solution.

I have tested printing the image file directly from Windows Photo Viewer as well as from the label program itself with success. The issue only occurs when running the program using PrintDocument. The following is my code

    var printDoc = new PrintDocument {PrinterSettings = {PrinterName = printerName}};
    printDoc.PrintPage += (sender, args) =>
    {
        using(Image img = Image.FromFile(filePath))
        {   //file is 900x300, DPI 300, and print page is 3x1 inches
            args.Graphics.PageUnit = GraphicsUnit.Document;
            args.Graphics.DrawImage(img, 0, 0, img.Width, img.Height);
            args.HasMorePages = false;
        }
    };

    printDoc.Print();

I have tried to set the width and height to a much smaller value when I draw the image but it will still print a blank label! Any help would be greatly appreciated.

lilbean
  • 35
  • 1
  • 9
  • Make sure your printer isn't configured to print a separator page. The posted code doesn't duplicate the problem for me, If you print to a PrintPreviewDialog, do you get the extra page? – LarsTech Dec 06 '17 at 20:18
  • The PaperSize tends to matter, it should match the label stock loaded into the printer. Why it would work well in PhotoViewer but not in a program that doesn't seem to select any paper size is hard to guess. – Hans Passant Dec 06 '17 at 20:29
  • @LarsTech, Thanks! I doubled checked that no separator page is set or even tried removing the setting to read the media based on label gaps with no luck. I will try the print preview dialog to see what happens – lilbean Dec 06 '17 at 20:58
  • @HansPassant I tried setting the PaperSize but without any luck either. Thanks for your suggestion! – lilbean Dec 06 '17 at 21:06
  • Call Zebra for support, you are using their printer driver. – Hans Passant Dec 06 '17 at 21:08

1 Answers1

0

I realized the issue. This only occurs running the program as a windows service. It will override any settings you have to the locally mapped printer and use the default network printer settings. Running the program as a console app worked as expected. The solution was to configure the default printer from its network location!

Many thanks to everyone who left comments and helped :)

lilbean
  • 35
  • 1
  • 9