将 PDF 标签打印到 Zebra 打印机 (420d)

Printing PDF lables to a Zebra printer (420d)

在我的网店中,我可以将送货单下载为 pdf 文件。我已经构建了一个使用 FileSystemWatcher 的 .NET 服务来监视我的“打印”文件夹。该服务将处理文件夹内的所有 .pdf.zpl 文件。

所有 .zpl 文件将使用 RawPrinterHelper class 使用 Windows 驱动程序直接打开并写入 Zebra 420d 打印机。它按预期工作!

我的问题是 .pdf 文件。当我从 Windows 10 中的浏览器手动打印文件到 Zebra 420d 打印机时,它工作得很好。但是当我尝试通过我的服务打印它们时,标签的尺寸会非常小。好像内容缩水了

public static bool PrintPdf(string filepath, string printerName)
{
    try
    {
        var doc = new PdfDocument();
        doc.LoadFromFile(filepath);
        doc.PrinterName = printerName;
        doc.PrintDocument.Print();
        doc.Dispose();

        return true;
    }
    catch (Exception ex)
    {
        // More code ...
    }
}

我整晚都在谷歌上搜索并尝试了各种方法将 PDF 转换为 PNG/SVG 到 ZPL,但没有成功。

如何使用 C# 将 PDF 格式的标签打印到 Zebra 420d 打印机?

编辑:我还尝试将 PDF 转换为 BMP,然后再转换为 GRF(Zebras 母语)。还是行不通。我得到的只是一个空白页。

我解决了!

我根本不需要任何转换。我只需要重新安装和调整打印机驱动程序设置并修改我的代码即可使用新设置。

这是我的最终代码:

 public static bool Print(string filepath, string printerName)
    {
        try
        {
            var doc = new PdfDocument();
            doc.LoadFromFile(filepath);
            doc.PrinterName = printerName;

            var psize = new PaperSize("Custom Paper Size", 417, 1007);
            doc.PrintDocument.DefaultPageSettings.PaperSize = psize;
            doc.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle180;

            doc.PrintDocument.Print();
            doc.Dispose();

            return true;
        }
        catch (Exception ex)
        {
            // More code ...
        }
    }

从 nuget 包下载器下载 Spire.Pdf 包以访问 PdfDocument class