1
votes

In my webshop, I'm able to download a delivery slip as a pdf file. I have built a .net service that uses FileSystemWatcher that monitors my "Print" folder. The service will process all .pdf and .zpl files inside the folder.

All .zpl files will be opened and written to a Zebra 420d printer directly using the Windows drivers using the RawPrinterHelper class. It works as expected!

My issue is the .pdf files. When I print the files manually from a browser in Windows 10 to the Zebra 420d printer, it works perfectly fine. But when I try to print them from my service, the size of the label will be very small. It looks like the content has shrunk.

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 ...
        }
    }

I have googled all night and tried various ways to convert a PDF to PNG/SVG to ZPL, but non worked.

How can I print labels in PDF-format to a Zebra 420d printer using c#?

Edit: I tried also to convert the PDF to a BMP and then to GRF (Zebras native language). Still not working. All I get is a blank page.

2
Exactly what I thought, not many that knows what ZPL is :)Dandy

2 Answers

0
votes

I solved it!

I didn't need any conversion at all. I had only to reinstall and adjust the printer driver settings and modify my code to work with the new settings.

This is my final code:

 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 ...
        }
    }
0
votes

Download Spire.Pdf package from nuget package downloader to access PdfDocument class