Printing to multiple trays from 1 document

Hi, when using v9.3, I find I’m able to print to multiple trays in a document just fine so long as the printer trays conform to the PrintTray enum values. However, if this isn’t the case, then the printer doesn’t correctly print to the right tray.
e.g. User selects tray 2 for page 1 and tray 3 for page 2 and onwards from printer x and it correctly prints. However, when selecting a different printer where tray 2 is actually tray 260 on the printer and tray 3 is actually 261 on the printer then this doesn’t actually work. They both just print to Tray 3 on the printer, or rather 261.
I had read that v9.5 should support tray numbers as your now just assing an int to FirstPageTray and OtherPagesTray, however, when using 9.5 I find that the automatic value is used for all printers, so it actually makes the problem worse.
When selecting these values in word for the printer, everything prints fine.
Below is my method for printing with Aspose.
If you could check it out and see if you notice any settings or values I may have used incorrectly. This is the version of the file used when using Aspose.Words 9.5 not 9.3 as the trays have not been cast to the specified enum.

private const int cAUTOMATICALLY_SELECT = 15;

publicstatic void Print(string inputFile, string printerName, int duplexMode, int firstTray, int followerTray, bool hasAttachments)
{
    PrinterSettings settings = new PrinterSettings();
    if (!printerName.IsNullOrEmpty())
        settings.PrinterName = printerName;
    if (duplexMode == 1 || duplexMode == 2 || duplexMode == 3 && settings.CanDuplex)
        settings.Duplex = duplexMode == 1 ? Duplex.Simplex : duplexMode == 2 ? Duplex.Vertical : Duplex.Horizontal;
    Document doc = new Document(inputFile);
    // If the batch is on the same tray, then just print it. If the batch is on seperate trays with no attachments
    // then just set the trays and print, if the batch is on seperate trays with attachments, then seperate each print
    // document to it's own print job.
    if (firstTray == followerTray && firstTray != cAUTOMATICALLY_SELECT) //if cAUTOMATICALLY_SELECT then don't set the printer trays at all.
    {
        foreach (Section section in doc.Sections)
        {
            section.PageSetup.FirstPageTray = firstTray;
            section.PageSetup.OtherPagesTray = firstTray;
        }
        settings.PrintRange = PrintRange.AllPages;
        doc.Print(settings);
    }
    // If automatically select, then don't override the values as tray's may be set in the document templates.
    else if (firstTray == followerTray && firstTray == cAUTOMATICALLY_SELECT)
    {
        settings.PrintRange = PrintRange.AllPages;
        doc.Print(settings);
    }
    else
    {
        settings.FromPage = 1;
        settings.ToPage = settings.FromPage;
        settings.PrintRange = PrintRange.SomePages;
        foreach (Section section in doc.Sections)
        {
            section.PageSetup.FirstPageTray = firstTray;
            section.PageSetup.OtherPagesTray = firstTray;
        }
        doc.Print(settings);
        doc = new Document(inputFile);
        if (doc.PageCount > 1)
        {
            settings.FromPage = 2;
            settings.ToPage = doc.PageCount;
            settings.PrintRange = PrintRange.SomePages;
            foreach (Section section in doc.Sections)
            {
                section.PageSetup.FirstPageTray = followerTray;
                section.PageSetup.OtherPagesTray = followerTray;
            }
            doc.Print(settings);
        }
    }
}

Regards
Nolan
Apologies for some of the formatting, it didn’t quite copy across correctly.

Hello,
Thank you for your request.
Could you please specify which printer (model) you use to print the document. And please provide as your file you are trying to print, and parameters firstTray and followerTray, which you pass to the procedure. I will try to simulate your problem and provide you with more detailed information.

Hi,
The first printer that worked for 9.3 is a Xerox ‘FX DocuCentre-III C2200 PCL 6’ . This printer does not print correctly using 9.5.
The 2nd printer that doesn’t appear to work at all due the tray numbers is ‘HP LaserJet P3010 Series PCL 6v’
I have attached the test document. Both trays are set to Default Tray in the document so should not override the setting used in the program.

Hello,
Thank you for additional information.
Unfortunately I was not able to sufficiently reproduce your option. But I made a similar to yours. Here is what I got.
I use “FX DC-II C2200 PCL” printer (that what i can find).
I created a document (in the enclosure), there are two sections, one page is an envelope, the second is a normal page.
Programmaticaly set up what trays to be used under any needs. In the end I managed to print a document from different trays.
Here is a screenshot of the trays installed in the document.
You need to do about the same. Create the necessary sections in a document of where pages will be printed. And assign these partitions to the necessary trays.
That the code I used:

var license = new License();
license.SetLicense("Aspose.Words.lic");
Document doc = new Document("X:\\trays.docx");
System.Drawing.Printing.PrinterSettings settings = new System.Drawing.Printing.PrinterSettings();
settings.PrinterName = "FX DC-II C2200 PCL";
// The tray used for A4 paper size.
const int printerTrayForA4 = 259;
// The tray used for Letter paper size.
const int printerTrayForLetter = 258;
// Set the page tray for each section based off the paper size used in the section.
foreach(Section section in doc.Sections)
{
    if (section.PageSetup.PaperSize == PaperSize.Custom)
    {
        section.PageSetup.FirstPageTray = printerTrayForLetter;
        section.PageSetup.OtherPagesTray = printerTrayForLetter;
    }
    else if (section.PageSetup.PaperSize == PaperSize.Letter)
    {
        section.PageSetup.FirstPageTray = printerTrayForA4;
        section.PageSetup.OtherPagesTray = printerTrayForA4;
    }
}
doc.Print(settings);
doc.Save(string.Format("X:\\out.docx"), SaveFormat.Docx);

Hope this helps.

Hi, I’d like to thank you for your detailed reply, however, it doesn’t correctly represent a solution to my request.
In your example you have different page types and you’ve set the page section based on this. In my case, I don’t want the document to have any settings in it at all. I just want to be able to set the trays and for them to correctly print.
As you can see in my example, page 1 of the document has all sections set to tray X and then all other pages are set to have their sections set to tray Y. Now this simply doesn’t appear to work on either of my printers.
I’ve attempted to save the document after I’ve updated the trays, however, this doens’t appear to help either.
The only thing I’ve been able to get the document to do is to print to the first tray, but never the 2nd tray. This is when I tray and print page 1 and subsequent pages seperately. If I set the trays at the same time and print the document as one whole document it will work on the Xerox printer, but not the HP as stated in my original call.
Any further help you can give with this would be much appreciated. I’ll keep working on it at my end and hopefully we can get this resolved asap.
Thanks
Nolan

Hi, further to this, I have now upgraded to version 9.8 and have also made quite a few code modifications, this has certainly moved things along.
Outstanding issues I have are that when printing to the HP printer and trays are set in the document but are NOT set in any way via the code, then the document is still printed to the default trays, not those set in the document.
When printing to the HP printer and settings.Duplex is set to Duplex.Vertical, it prints on the horizontal. So not sure what’s going on with this, as it works fine on the Xerox.
Cheers

Hello,
Thank you for additional information. I need a little more time to investigate your problem. I will try to answer you tomorrow. Sorry for the inconvenience.