Print a document to a specific tray

AsposeWordsPrintDocuments seems to loose the set PaperSource when printing. Because of this we cannot set or print to the correct papertray which is causing a serious production disturbance. Source code below demonstrates how to reproduce this problem.

using Aspose.Words;
using Aspose.Words.Rendering;
using System;
using System.Drawing.Printing;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            new PrintDoc();
        }
        public class PrintDoc
        {
            public PrintDoc()
            {
                Document doc = new Document(); //insertdocument
                PrintDocument printDoc = new PrintDocument();
                // AsposeWordsPrintDocument printDoc = new AsposeWordsPrintDocument(doc);
                PrinterSettings printerSettings = new PrinterSettings();
                printerSettings.PrinterName = "HP LaserJet 4100 Series PS";
                printDoc.PrinterSettings = printerSettings;

                pageSettings = new PageSettings();
                PaperSource source = new PaperSource(); //RawKind default: 257
                source.RawKind = 262;
                pageSettings.PaperSource = source;
                printDoc.QueryPageSettings += new QueryPageSettingsEventHandler(printDoc_QueryPageSettings);
                printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
                printDoc.Print();
            }
            public void printDoc_QueryPageSettings(object sender, QueryPageSettingsEventArgs ev)
            {
                ev.PageSettings = pageSettings;
                Console.Write(ev.PageSettings.PaperSource.RawKind); //RawKind= PrintDocument: 262, AsposeWordsPrintDocument: 262
            }
            public void printDoc_PrintPage(object sender, PrintPageEventArgs ev)
            {
                Console.Write(ev.PageSettings.PaperSource.RawKind); //RawKind= PrintDocument: 262, AsposeWordsPrintDocument: 0
            }
            private PageSettings pageSettings;
        }
    }
}

Hello,
Thank you for your request.
Unfortunately I was unable to reproduce your problem.
I used your code but with a different printer. I took the "Xerox WC 4118 Series PCL 6 ". There are four tray.
Kind = AutomaticFeed (RawKind = 7)
Kind = Upper (RawKind = 1)
Kind = ManualFeed (RawKind = 6)
Kind = Manual (RawKind = 4)
I print to all trays:

source.RawKind = 7;
pageSettings.PaperSource = source;
printDoc.Print();
source.RawKind = 1;
pageSettings.PaperSource = source;
printDoc.Print();
source.RawKind = 6;
pageSettings.PaperSource = source;
printDoc.Print();
source.RawKind = 4;
pageSettings.PaperSource = source;
printDoc.Print();

I take off output from the console. And I see exactly the numbers that expected. “77116644”.
Most likely you have not correctly entered number custome tray.

Hi there,
In addition to what Viktor has said, please also make sure you are using the latest version of Aspose.Words available from here.
There was an issue very similar to the one you are describing here that was recently fixed.
Thanks,

Tried it again using the latest Aspose.Words version (9.7.0). The problem still reproduces. Although I do notice a slight change; the RawKind in the PrintPageEventArgs changed from 0 (AW 9.5.0) to 15 (AW 9.7.0), which is Automatically Select.
Also: please make sure you’re executing with the AsposeWordsPrintDocument instead of the System.Drawing.PrintDocument.
Is there workaround we can use to provide our own implementation of the PrintPage eventhandler?

Hi
Thank you for additional information. Does the problem occur with any document on your side or only with a particular document? Could you please attach a sample document here for testing? We will check it on our side and try to help you to resolve the problem.
Best regards,

It reproduces with any document. Printing to different trays works for any document using PrintDocument, but I don’t want to have to provide my own implementation for PrintPage (for the obvious reasons). Thanks for your help.

Hi
Thanks for your request. Upon printing Aspose.Words uses paper trays specified in the document. In your document Default tray is specified. That is why Aspose.Words prints your document to default tray.
Best regards,