package.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  2. <!-- package.html - describes classes in javax.print package.
  3. Copyright (C) 2003, 2006 Free Software Foundation, Inc.
  4. This file is part of GNU Classpath.
  5. GNU Classpath is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. GNU Classpath is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GNU Classpath; see the file COPYING. If not, write to the
  15. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA.
  17. Linking this library statically or dynamically with other modules is
  18. making a combined work based on this library. Thus, the terms and
  19. conditions of the GNU General Public License cover the whole
  20. combination.
  21. As a special exception, the copyright holders of this library give you
  22. permission to link this library with independent modules to produce an
  23. executable, regardless of the license terms of these independent
  24. modules, and to copy and distribute the resulting executable under
  25. terms of your choice, provided that you also meet, for each linked
  26. independent module, the terms and conditions of the license of that
  27. module. An independent module is a module which is not derived from
  28. or based on this library. If you modify this library, you may extend
  29. this exception to your version of the library, but you are not
  30. obligated to do so. If you do not wish to do so, delete this
  31. exception statement from your version. -->
  32. <html>
  33. <head><title>GNU Classpath - javax.print</title></head>
  34. <body>
  35. Provides the basic interfaces and classes of the Java Print Service API.
  36. <p>
  37. The Java Print Service API enables programmers to:
  38. <ul>
  39. <li>Discover print services for printing to printer devices and to output
  40. streams. The discovery process can be constrained to return only print
  41. services supporting specific document formats or printing attributes.</li>
  42. <li>Print client-formatted print data like Postscript, PDF or various
  43. image formats and service-formatted print data from Java.</li>
  44. <li>Submit, cancel and monitor single and multi document print jobs.</li>
  45. <li>Provide users a graphical print service browser with printing attribute
  46. selection.</li>
  47. </ul>
  48. </p>
  49. <p>
  50. <h2>Print Service Discovery</h2>
  51. Print service types in the JPS API:
  52. <ul>
  53. <li><a href="PrintService.html">PrintService</a>:<br>The base interface
  54. describing a print service capable of printing a supplied document for a
  55. given document format to the printer device it is representing.</li><br>
  56. <li><a href="MultiDocPrintService.html">MultiDocPrintService</a>:<br>Extends
  57. the PrintService interface and provides a print service which is capable of
  58. printing multiple documents as one print job to its printer device.</li><br>
  59. <li><a href="StreamPrintService.html">StreamPrintService</a>:<br>Extends the
  60. PrintService interface and provides a print service which is capable of
  61. printing into a supplied output stream instead of to a physical printer
  62. device.</li>
  63. </ul>
  64. </p>
  65. <p>
  66. <h4>PrintService, MultiDocPrintService</h4>
  67. Discovery is done by the use of the static methods in the
  68. <a href="PrintServiceLookup.html">PrintServiceLookup</a> class. The discovery
  69. process can be constrained by supplying the document formats and printing
  70. attributes that need to be supported by the returned print service. Furthermore
  71. the <a href="PrintServiceLookup.html#lookupDefaultPrintService()">
  72. lookupDefaultPrintService()</a> method enables to lookup the default print
  73. service of the platforms printing system.
  74. </p>
  75. <p>
  76. <h4>StreamPrintService</h4>
  77. StreamPrintService provides the same functionality as a print service for output
  78. to a supplied <code>OutputStream</code>. Available stream print services are
  79. discovered via the static methods in the <a href="StreamPrintServiceFactory.html">
  80. StreamPrintServiceFactory</a> factory. The query can be constrained by supplying
  81. the the requested document format support and the needed output format.
  82. </p>
  83. <h2>Document formats</h2>
  84. The format of the printing documents are specified by the
  85. <a href="DocFlavor.html">DocFlavor</a> class in the JPS API. It provides the
  86. description of the format in which the print data will be supplied in a print
  87. job to the print service and consists of two parts:
  88. <ul>
  89. <li>The MIME type (Multipurpose Internet Mail Extensions types as described in
  90. RFC 2045/2046) specifying the media format of the print data.</li>
  91. <br>
  92. <li>The representation class name which is the fully qualified name of the
  93. class providing the print data to the print job. For example if the print data
  94. is supplied as a byte array the representation class name will be "[B" or for
  95. an input stream "java.io.InputStream".</li>
  96. </ul>
  97. The Java Print Service API differentiates between two types of print data,
  98. client-formatted and service-formatted. Client-formatted print data is already
  99. provided in a formatted representation by the client e.g. in an image format
  100. or as postscript. For service-formatted print data, the Java Print Service
  101. implementation produces the formatted print data. Here the doc flavor's
  102. representation class name does specify an interface instead of the actual
  103. print data source. The print service will call the methods of the given
  104. implementation of this interface with a special Graphics object capable of
  105. producing formatted print data from the graphics routines inside the
  106. interface methods.
  107. </ul>
  108. <h2>Printing attributes</h2>
  109. Print services as well as print jobs report their state and capabilities
  110. by the way of supplying printing attributes. Also the behaviour of print
  111. jobs (like how many copies should be printed) is controlled via printing
  112. attributes. For these requirements the JPS API defines different roles
  113. of attributes and common syntax classes in the package
  114. <code>javax.print.attribute</code>. The actual available printing attributes
  115. are implemented in the <code>javax.print.attribute.standard</code> package.
  116. <ul>
  117. <li>Print service attributes:<br>
  118. These printing attributes of role
  119. <a href="attribute/PrintServiceAttribute.html">PrintServiceAttribute</a> report
  120. the status and other informations of a PrintService. Example for informations
  121. available in the print services attributes are the attribute
  122. <code>PagesPerMinute</code> providing the number of pages a printer can print
  123. per minute. Status attributes like the <code>PrinterState</code> attribute
  124. gives the current state (e.g. printer currently processes or is idle) of the
  125. printer.</li>
  126. <br>
  127. <li>Print job attributes:<br>
  128. Print job attributes of role <a href="attribute/PrintJobAttribute.html">
  129. PrintJobAttribute</a> inform about the status of given print job. For example
  130. the <code>NumberOfInterveningJobs</code> attribute provides the number of jobs
  131. ahead in the print service queue before this job. Status attributes like the
  132. <code>JobState</code> attribute gives the current state of the print job (like
  133. pending, processing or canceled).</li>
  134. <br>
  135. <li>Print request attributes:<br>
  136. The attributes of role <a href="attribute/PrintRequestAttribute.html">
  137. PrintRequestAttribute</a> specify the behaviour of a complete print job.
  138. The print request attributes apply to all documents in a print job, whereas
  139. the doc attributes only apply to the specific document in a print job.
  140. Most of the print request attributes are also doc attributes and therefore
  141. implementing both attribute role interfaces.
  142. </li>
  143. <br>
  144. <li>Doc attributes:<br>
  145. As described above the <a href="attribute/PrintJobAttribute.html">
  146. PrintJobAttribute</a> attributes are specific to a single document in the
  147. print job.
  148. </li>
  149. </ul>
  150. <h2>Example of using the API</h2>
  151. <pre>
  152. import java.io.*;
  153. <br>
  154. import javax.print.*;
  155. import javax.print.attribute.*;
  156. import javax.print.attribute.standard.*;
  157. import javax.print.event.*;
  158. <br>
  159. public class Beispiel
  160. {
  161. &nbsp; public static void main(String[] args)
  162. &nbsp; {
  163. &nbsp; &nbsp; // Using the predefined doc flavor for postscript mimetype
  164. &nbsp; &nbsp; DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
  165. <br>
  166. &nbsp; &nbsp; // Looking for printservice supporting this doc flavor
  167. &nbsp; &nbsp; PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null);
  168. <br>
  169. &nbsp; &nbsp; // Just take the first
  170. &nbsp; &nbsp; PrintService service = services[0];
  171. &nbsp; &nbsp; System.out.println("Name :" + service.getName());
  172. <br>
  173. &nbsp; &nbsp; try
  174. &nbsp; &nbsp; &nbsp; {
  175. &nbsp; &nbsp; &nbsp; &nbsp; // Create a print job
  176. &nbsp; &nbsp; &nbsp; &nbsp; DocPrintJob job = service.createPrintJob();
  177. <br>
  178. &nbsp; &nbsp; &nbsp; &nbsp; // We want to print a file so we construct an inputstream
  179. &nbsp; &nbsp; &nbsp; &nbsp; // on the file to supply the print data as given in the doc flavor
  180. &nbsp; &nbsp; &nbsp; &nbsp; File file = new File("File.ps");
  181. &nbsp; &nbsp; &nbsp; &nbsp; InputStream stream = new FileInputStream(file);
  182. <br>
  183. &nbsp; &nbsp; &nbsp; &nbsp; // Build a attribute set with the wanted printing attributes
  184. &nbsp; &nbsp; &nbsp; &nbsp; HashPrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
  185. &nbsp; &nbsp; &nbsp; &nbsp; attr.add(new Copies(2)); // two copies
  186. &nbsp; &nbsp; &nbsp; &nbsp; attr.add(new PageRanges(2, 7)); // only the 2-7 pages
  187. <br>
  188. &nbsp; &nbsp; &nbsp; &nbsp; // Construct a doc object with the provided class SimpleDoc
  189. &nbsp; &nbsp; &nbsp; &nbsp; SimpleDoc doc = new SimpleDoc(stream, flavor, null);
  190. <br>
  191. &nbsp; &nbsp; &nbsp; &nbsp; // register us as the print - use the adapter class
  192. &nbsp; &nbsp; &nbsp; &nbsp; // and override the interesing failure condition
  193. &nbsp; &nbsp; &nbsp; &nbsp; job.addPrintJobListener(new PrintJobAdapter()
  194. &nbsp; &nbsp; &nbsp; &nbsp; {
  195. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void printJobFailed(PrintJobEvent arg0)
  196. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
  197. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("The PrintJob failed.");
  198. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
  199. &nbsp; &nbsp; &nbsp; &nbsp; });
  200. <br>
  201. &nbsp; &nbsp; &nbsp; &nbsp; // start the printing process
  202. &nbsp; &nbsp; &nbsp; &nbsp; job.print(doc, attr);
  203. <br>
  204. &nbsp; &nbsp; &nbsp; &nbsp; // lets assume we want to cancel it
  205. &nbsp; &nbsp; &nbsp; &nbsp; if (job instanceof CancelablePrintJob)
  206. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
  207. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CancelablePrintJob cancelJob = (CancelablePrintJob) job;
  208. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cancelJob.cancel();
  209. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
  210. <br>
  211. &nbsp; &nbsp; &nbsp; }
  212. &nbsp; &nbsp; catch (PrintException e)
  213. &nbsp; &nbsp; {
  214. &nbsp; &nbsp; &nbsp; e.printStackTrace();
  215. &nbsp; &nbsp; }
  216. &nbsp; &nbsp; catch (FileNotFoundException e)
  217. &nbsp; &nbsp; {
  218. &nbsp; &nbsp; &nbsp; e.printStackTrace();
  219. &nbsp; &nbsp; }
  220. &nbsp; }
  221. }
  222. </pre>
  223. <p>
  224. <b>Since:</b> 1.4
  225. </p>
  226. </body>
  227. </html>