PrintDocument 在打印作业上添加一个额外的空白页

PrintDocument adds an extra blank page upon a print job

当我用 Zebra 打印机打印图像标签时,标签打印正常,然后送入额外的空白标签,这随后会导致每个打印标签的上边距不对齐。

我在网上看了很多已经发布的问题(即),没有解决方案。

我已经测试过直接从 Windows 照片查看器以及标签程序本身打印图像文件并成功。该问题仅在 运行 程序使用 PrintDocument 时出现。以下是我的代码

    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();

我尝试在绘制图像时将宽度和高度设置为更小的值,但它仍然打印出空白标签!任何帮助将不胜感激。

我意识到了这个问题。这仅发生 运行 作为 windows 服务的程序。它将覆盖您对本地映射打印机的任何设置,并使用默认网络打印机设置。 运行 作为控制台应用程序的程序按预期运行。解决方案是从其网络位置配置默认打印机!

非常感谢所有留下评论和帮助的人:)