Printing the Java 1.4 Way : Print « 2D Graphics GUI « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. Email
14. Event
15. File Input Output
16. Game
17. Generics
18. Hibernate
19. I18N
20. J2EE
21. J2ME
22. JDK 6
23. JSP
24. JSTL
25. Language Basics
26. Network Protocol
27. PDF RTF
28. Reflection
29. Regular Expressions
30. Scripting
31. Security
32. Servlets
33. Spring
34. Swing Components
35. Swing JFC
36. SWT JFace Eclipse
37. Threads
38. Tiny Application
39. Velocity
40. Web Services SOA
41. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » 2D Graphics GUI » PrintScreenshots 
Printing the Java 1.4 Way

import java.io.FileInputStream;

import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.DocAttributeSet;
import javax.print.attribute.HashDocAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.event.PrintJobAdapter;
import javax.print.event.PrintJobEvent;
import javax.print.event.PrintJobListener;

public class PrintingOneFour {
  public static void main(String args[]) throws Exception {
    String filename = args[0];
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    PrintService printService = PrintServiceLookup
        .lookupDefaultPrintService();
    DocPrintJob job = printService.createPrintJob();
    PrintJobListener listener = new PrintJobAdapter() {
      public void printDataTransferCompleted(PrintJobEvent e) {
        System.out.println("Good-bye");
        System.exit(0);
      }
    };
    job.addPrintJobListener(listener);
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    FileInputStream fis = new FileInputStream(filename);
    DocAttributeSet das = new HashDocAttributeSet();
    Doc doc = new SimpleDoc(fis, flavor, das);
    job.print(doc, pras);
    Thread.sleep(10000);
  }
}
           
       
Related examples in the same category
1. Print an Image to print directly
2. Simplest SWT Print ExampleSimplest SWT Print Example
3. Print in Java 2: PrinterJob
4. Print in Java: page format and document
5. Print in Java: Multi page
6. Print in Java 5
7. Print in Java 6
8. Simple Book for printingSimple Book for printing
9. Shapes PrintShapes Print
10. Display the print dialog and print
11. Print the printable area outlinePrint the printable area outline
12. Print the text file and print preview themPrint the text file and print preview them
13. Printable demoPrintable demo
14. Print Swing componentsPrint Swing components
15. BookBook
16. Another print demoAnother print demo
17. Book demoBook demo
18. Printing the Combined-Java 1.2-and-1.4 WayPrinting the Combined-Java 1.2-and-1.4 Way
19. Prompting for a Printer
20. Printing the Java 1.1 WayPrinting the Java 1.1 Way
21. ScribbleScribble
22. Printable Document
23. PrintFile -- Print a file named on the command linePrintFile -- Print a file named on the command line
24. Print to the standard output
25. PrintPanel is the base for an open-ended series of classesPrintPanel is the base for an open-ended series of classes
26. Print Demo: BookPrint Demo: Book
27. Print Test Print Test
28. Pageable TextPageable Text
29. Printable Component
w_w_w.___j_a___va_2___s___.___co_m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.