The Spring Integration Print allows you to print payloads using the Java Print Service. As such one Outbound Channel Adapter is provided.
This module depends by default on Spring Integration 2.2. When using this module, please be aware that printing using Java Print Service can be unpredictable depending on the uses platform and the used printer. For some more details, please see:
Currently the Print Support has been tested using a Brother HL-4070CDW which exhibits several issues such as the inability to execute a print job that prints more than one copy for each page. If you use the Print Module, please report back any compatibility issues with your used printers.
dependencies {
…
compile "org.springframework.integration:spring-integration-print:1.0.0.BUILD-SNAPSHOT"
…
}
<dependencies>
…
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-print</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
…
</dependencies>
The Print Outbound Channel Adapter is implemented using the PrintMessageHandler class. It in turn delegates to the PrintServiceExecutor class. The PrintServiceExecutor is responsible for initializing the Java PrintService. As such, you can initialize the PrintServiceExecutor with providing a:
- Printer Name
- Custom implementation of the PrintService interface (Useful for testing)
If you provide neither a printer name nor an implementation of the PrintService interface, then the systems default printer is chosen.
The following properties can be set on the Print Outbound Channel Adapter:
Optional property that let's you specify the name of the print job as it is added to the print queue. Under the covers, this property will create a javax.print.attribute.standard.JobName and add it to the respective PrintRequestAttributeSet. This property is not used, if not specified (No explicit default value).
Optional property that let's you specify the MediaSizeName. Under the covers, this property will add the provided MediaSizeName to the respective PrintRequestAttributeSet. This property is not used, if not specified (No explicit default value).
Let's you specify how the pages are are printed to the selected medium, e.g. duplex or one-sided. Under the covers, this property will add the provided Sides instance to the respective PrintRequestAttributeSet. This property is not used, if not specified (No explicit default value).
Let's you specify an integer value that indicates how many time each print page shall be printed. Under the covers, this property will add a Copies instance to the respective PrintRequestAttributeSet. This property is not used, if not specified (No explicit default value).
Let's you specify the media tray/bin for the print job. This property can be used instead of providing the mediaSizeName property. Under the covers, this property will add the provided MediaTray instance to the respective PrintRequestAttributeSet. This property is not used, if not specified (No explicit default value).
Let's you specify whether you want to do monochrome or color printing. Under the covers, this property will add the provided Chromaticity instance to the respective PrintRequestAttributeSet. This property is not used, if not specified (No explicit default value).
Let's you specify the DocFlavor. If not specified, this property will default to DocFlavor.STRING.TEXT_PLAIN.
IMPORTANT! Every property is validated against the to be used Java Print Service. Therefore, if the selected Java Print Service is not supported, an IllegalArgumentException will be thrown.
In order to get some indication what capabilities are supported by your printer, you may want to too look at the PrintServiceExecutor's getPrinterInfo() method. When executed, it returns a list of:
- Supported DocFlavors
- Supported Attribute Categories
- Supported Print Attributes
Spring Integration also provides XML Namespace support for the Print support. Simply add the following Namespace declaration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-print="http://www.springframework.org/schema/integration/print"
xsi:schemaLocation="
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/print https://www.springframework.org/schema/integration/print/spring-integration-print.xsd">
…
</beans>
An example of declaring a Print Outbound Channel Adapter is shown below:
<int-print:outbound-channel-adapter id="printOutboundChannelAdapter"
channel="input"
copies="2"
doc-flavor="java.lang.String"
mime-type="text/plain; charset=utf-8"
sides="DUPLEX"/>