FREE Spire.PDF - Zebra printing PDF out of bounds

A Anton Engels 2 years 10 months ago
118 1 0

Hi,

For the past week or so I've been trying to print PDF files to our Zebra ZT220 printer from C# using the FREE Spire.PDF NuGet component. Everything went pretty smoothly when testing the functionality from a WinForms GUI, i.e. when clicking the 'Print' button I had put up there.

This all changed when I deployed the same code to run from a Windows Service. The printing still got done, i.e. the PDF file was sent to the Zebra ZT220 printer, but it seemed to mess up where on the label to start printing. Now only the upper left corner of our 10x15 cm label has something printed on it.

I'm guessing for some reason the printer settings that are picked up when printing from a GUI aren't honored/used when doing the same from a Windows Service.

Any idea's on how to fix this? Do I have to specify what the bounds / margins of the document are before printing or can I somehow make C# use the printer settings from a Windows Service, same as it does from a GUI?

Note: Up until now I've pretty much only used 'PdfPrintPageScaling.ActualSize' as page scaling.

I hope you can help. Thanks in advance.

Below is the code I'm using at the moment:

PdfDocument document = new PdfDocument();int scalingPerc = 0;if (scaling == "Aangepaste schaal"){     if (scalingPercentage != -1)     {          document.PageScaling = PdfPrintPageScaling.CustomSacle;          document.CustomScaling = scalingPerc;     }     else     {          return;     }}else if (scaling == "Passend"){     document.PageScaling = PdfPrintPageScaling.FitSize;}else if (scaling == "Ware grootte"){     document.PageScaling = PdfPrintPageScaling.ActualSize;}else if (scaling == "Te grote pagina's verkleinen"){     document.PageScaling = PdfPrintPageScaling.ShrinkOversized;}string extension = Path.GetExtension(filePath);if (extension.ToLower() == ".pdf"){     try     {          document.LoadFromFile(filePath);                    PrintDocument printDoc = document.PrintDocument;          printDoc.PrinterSettings.PrinterName = printerName;          if (!String.IsNullOrEmpty(printerLadeSourceName)) // printerlade gekozen          {               for (int i = 0; i printDoc.PrinterSettings.PaperSources.Count; i++)               {                    string ladeSourceName = printDoc.PrinterSettings.PaperSources[i].SourceName;                    if (printerLadeSourceName.ToUpper() == ladeSourceName.ToUpper()) // lade komt overeen                    {                         printDoc.DefaultPageSettings.PaperSource = printDoc.PrinterSettings.PaperSources[i];                         break;                    }               }          }          printDoc.Print();          printDoc.Dispose();     }     catch (Exception ex)     {          // log error     }}

Please register or login to post a reply

1 Replies

V Vedsatx Saddvv

Hi Anton, When you said that only the upper left corner was printed, does that mean the entire label was scaled to fit in that corner, or that the image was scaled right but just cut off and only showing that corner?
Are you printing to a driver or do you have a PDF virtual machine running on the printer?  Which driver version?
Thanks

CONTACT
Can’t find what you’re looking for?