We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Document printed on wrong trays

Hi There,

I setup the tray info in docx file and print document with the following code snippet
doc = new Document(“test.docx”);
doc.print("\\printsrv\AA4 Printer - FL9");

However, the pages always printed in reversed tray order
Eg. I setup the first page to print in tray 1 and the other pages in tray 2. Then, the page 1 printed on tray 2 and the other pages printed on tray 1 AND vise versa

Note: I have tried this on several different printers “HP LaserJet Pro M402-M403 n-dn PCL 6” and “HP LaserJet P2035n” with different Aspose Word version of 19.4 (latest one and trial) and 17.2.0 (License)

Regards

Dat

@dat.do

Microsoft Word stores printer specific values for paper trays in a Word document and therefore, only printing on the same printer model as the one that was selected when the user specified the paper trays will result in printing from the correct trays. If you print a document on a different printer, then most likely the default paper tray will be used, not the trays specified in the document.

You can try the following code example to get the desired output.

Document doc = new Document(MyDir + "in.docx");

System.Drawing.Printing.PrinterSettings settings = new System.Drawing.Printing.PrinterSettings();

// The paper tray value stored in documents is completely printer specific. This means
// The code below resets all page tray values to use the current printers default tray.
// You can enumerate PrinterSettings.PaperSources to find the other valid paper tray values of the selected printer.

foreach (Section section in doc.Sections)
{
    section.PageSetup.FirstPageTray = settings.DefaultPageSettings.PaperSource.RawKind;
    section.PageSetup.OtherPagesTray = settings.DefaultPageSettings.PaperSource.RawKind;
}

doc.Print(settings);

Hi Tahir,

Thank for your quick response.

From your response I can see that the code you provided seems to be C#. I’m using Apose Word for Java and I cannot find the PrinterSettings. Can you please show me where can I find that?

Thanks

Dat

@dat.do

You can use the following Java code to set the FirstPageTray and OtherPagesTray properties.

// Find the printer that will be used for printing this document. In this case it is the default printer.
// You can define a specific printer by using PrintServiceLookup.lookupPrintServices.
PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
Media defaultTray = (Media) printService.getDefaultAttributeValue(Media.class);

// The paper tray value stored in documents is completely printer specific. This means
// The code below resets all page tray values to use the current printers default tray.
// You can enumerate getSupportedAttributeValues for Media type to find the other valid
// paper tray values of the selected printer.
for (Section section : doc.getSections()) {
    section.getPageSetup().setFirstPageTray(defaultTray.getValue());
    section.getPageSetup().setOtherPagesTray(defaultTray.getValue());
}

Hi Tahir,

Thanks for your response I appreciate that. I just have one more concern is that the tray numbers setup/stored in document somehow differ from the tray numbers retrieved from PrintService.getSupportedAttributeValues
Eg. I setup tray 1 for page 1 and tray 2 for the order pages. Then, I get tray number from the document and I get values of 1 and 3 corresponding. However, the tray number I can get from the PrintService are 0, 1 and 4 (default)

So, my question is how to map these numbers to make it print on correct tray?

Thanks
Dat

@dat.do

Please note that MS Word’s behavior for paper tray value is completely implementation specific.

If you create a document in Microsoft Word and set paper tray values, the values stored in the document will be for the currently selected (or default maybe) printer. For example, the value of 292 will be stored inside the Word document.

Then, when you take this document to another computer that has a different printer installed and try to print it (or just check in Page Setup to see what paper tray is selected), you will observe that the paper tray is not preserved! It is reset to a default value.

What this all means is that you can only expect the paper tray to be correctly handled by Microsoft Word when printing on the same printer model as the one that was selected when the paper trays were selected.

There are no “universal” or “well known” values for paper trays stored in Word documents. To fix the problem and print to the correct paper trays, please set the value of PageSetup.FirstPageTray and OtherPagesTray properties to simple integers.

Hi Tahir,

I have setup paper tray for the document and used Aspose Java API to print on the same printer. However, it still be printed on the reversed paper tray order. Do you have any suggestion?

Thanks

Dat

@dat.do

Please set these values to FirstPageTray and OtherPagesTray.