Selecting printers

From NOA Documentation Wiki

Jump to: navigation, search

Printing is very easy with NOA, just use ITextDocument's print() function.

This, however, does not give you the full power of UNO.

If you dive a bit deeper, e.g. because, you want to print on a particular device, you'll like the following code, which will print on a device called "SamplePrinterName" (based on:http://ubion.ion.ag/mainForumFolder/noa_forum/0069?b_start:int=0#0014):

			// Setting the property "Name" for the favoured printer (name of
//			IP address)
			PropertyValue[] propertyValue =
				new com.sun.star.beans.PropertyValue[2];

//			Querying for the interface XPrintable on the loaded document
			com.sun.star.view.XPrintable xPrintable =
				(com.sun.star.view.XPrintable)UnoRuntime.queryInterface(
						com.sun.star.view.XPrintable.class, this.getDocument().getXComponent());

//			set print parameters
			propertyValue[0] = new com.sun.star.beans.PropertyValue();
			propertyValue[0].Name = "Name";
			propertyValue[0].Value = "SamplePrinterName";

//			wait until print is finished
			propertyValue[1] = new com.sun.star.beans.PropertyValue();
			propertyValue[1].Name = "Wait";
			propertyValue[1].Value = new Boolean(true);

//			Setting the name of the printer
			try {
				xPrintable.setPrinter( propertyValue );
// print!				
				xPrintable.print(propertyValue);
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

In this example, this.getDocument() just returns the ITextDocument, so a version without the possibility of setting a custom printer could have looked like

this.getDocument().print();
Personal tools