Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Nov 16, 2018 7:21 am

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:

Code: Select all
            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
                }
            }


Kind regards,

Anton

morfinpump
 
Posts: 1
Joined: Fri Nov 16, 2018 6:55 am

Fri Nov 16, 2018 9:04 am

Hi,

Thanks for your inquiry.
Kindly note that the free Spire.PDF is not very stable, and we have no plan to update it. By contrast, the commercial Spire.PDF has better optimization and more features than the free Spire.PDF. Please use the Commercial Spire.PDF instead. Below is the Commercial Spire.PDF download link.
https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
Please refer to the tutorial of the new method to print the PDF file from the following link.
https://www.e-iceblue.com/Tutorials/Spi ... -in-C.html
If the issue still exists, please send your sample file to us via email(support@e-iceblue.com).
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Fri Nov 23, 2018 9:53 am

Hi,

Greeting from e-iceblue.
Has your issue been resolved? Could you please give us some feedback about your issue?
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Return to Spire.PDF