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

Free Support Forum - aspose.com

AsposeWordsPrintDocument loses print trays - java

Hi, i use following code to open a aspose words document and print it.
the original document has 2 pages ,is printed on a existing printer, the first page has to be printed on tray-2 and all following pages on tray-3.
When printing with Microsoft Word, the document tray settings are respected and printing works.

But with AsposeWordsPrintDocument, the tray-settings are lost.

import java.awt.print.PrinterJob;
import java.io.File;
import java.io.FileInputStream;

import javax.print.PrintService;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;

import com.aspose.words.AsposeWordsPrintDocument;
import com.aspose.words.Document;
import com.aspose.words.License;

public class TestAsposePrint {

/**

  • @param args
  • @throws Exception
    */
    public static void main(String[] args) throws Exception {

Document doc = new Document(“C:\test.doc”);
String printerName = “\server\printer_1”;

PrinterJob pj = PrinterJob.getPrinterJob();
PrintService[] service = PrinterJob.lookupPrintServices();
for (PrintService printService : service) {
if(printService.getName().contains(printerName)){
pj.setPrintService(printService);
break;
}
}

// Create the Aspose.Words’ implementation of the Java Pageable interface.
AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc);

// Pass the document to the printer.
pj.setPageable(awPrintDoc);

// Print the document with the user specified print settings.
pj.print();

}

}

i do not want to use the printDialog, the documents are printed in batch.

Could you please look into this, do i need to map the trays from the document to printattributes or should this code work ?

thanks in advance.
With kind regards,
Paul Kwakman

@PaulKwakman

Thanks for your inquiry. We suggest you please use Document.Print(PrinterSettings) method. This method prints the document according to the specified printer settings, using the standard (no User Interface) print controller.

Please note that Aspose.Words reads values from document in Raw format (i.e. as int) and after Print method is called, a function compares the Raw value of PaperTray of current page and values in PrinterSettings.PaperSources and if it doesn’t find coincidence, function returns “Automatic” value. Then it passes the value for PaperTray to underlying Windows function that actually sends document to printer.

You should also note that paper tray numbers are printer specific. The problem might occur because paper trays numbers specified in your document do not match paper tray numbers of the printer running on your local environment. So, first of all you should make sure that paper trays in your document are specified correctly.

In Microsoft Word printer trays are defined per section and are printer specific. Therefore you can programtically change these values by using the FirstPageTray and OtherPagesTray properties of the PageSetup class for each section.

Hi Tahir,

thanks a lot for your answer, it works fine!

This solves the problem for customers with an actual printer connected to the server.
But when customers do not have that, we use the document.save(filename,SaveFormat.XPS) method.
The documents are generated on the server and copied to a client pc and send to the queue.
After opening the xps file, the tray-information is no longer there.

is it possible to save the tray-settings after exporting to XPS ?

again, thanks a lot for your help!

with kind regards,
Paul

@PaulKwakman

Thanks for your inquiry. Unfortunately, the paper tray information is not stored in XPS file. However, this information is stored in PCL file format when you convert your document to PCL.