
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

import javax.print.PrintService;

public class HelloPrintingWithoutDialog implements Printable{
	
	public HelloPrintingWithoutDialog() {
		PrintService ps = getPrintService();
		PrinterJob   job = PrinterJob.getPrinterJob();
		try {
			job.setPrintService(ps);
			job.setPrintable(this);
			job.print();
		} catch (PrinterException e) {
			e.printStackTrace();
		}
	}
	
	public PrintService getPrintService() {
		PrintService[] services = PrinterJob.lookupPrintServices();
		
		for (PrintService service : services) {
			System.out.println(service.getName());
		}
		
		return services[0];
	}
	
	@Override
	public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
		if (page > 0) {
			return NO_SUCH_PAGE;
		}
		
		Graphics2D g2d = (Graphics2D)g;
		g2d.translate(pf.getImageableX(), pf.getImageableY());
		
		g.setFont(new Font("Verdana", Font.PLAIN, 12));
		g.drawString("Hello Printing without Dialog!", 0, 10);
		
		return PAGE_EXISTS;
	}
	public static void main(String...args) {
		System.out.println("Hello Printing without Dialog!");

		new HelloPrintingWithoutDialog();
	}
}

@@ -1,25 +1,24 @@
-%0A
 import java.awt.Font;%0Aim
@@ -309,13 +309,16 @@
 able
+ 
 %7B%0A
-%09%0A%09
+%0A    
 publ
@@ -347,26 +347,32 @@
 tDialog() %7B%0A
-%09%09
+        
 PrintService
@@ -396,18 +396,24 @@
 vice();%0A
-%09%09
+        
 PrinterJ
@@ -415,18 +415,16 @@
 nterJob 
-  
 job = Pr
@@ -453,19 +453,34 @@
 ();%0A
-%09%09try %7B%0A%09%09%09
+        try %7B%0A            
 job.
@@ -496,27 +496,36 @@
 ervice(ps);%0A
-%09%09%09
+            
 job.setPrint
@@ -536,19 +536,28 @@
 (this);%0A
-%09%09%09
+            
 job.prin
@@ -561,18 +561,24 @@
 rint();%0A
-%09%09
+        
 %7D catch 
@@ -600,19 +600,28 @@
 on e) %7B%0A
-%09%09%09
+            
 e.printS
@@ -637,18 +637,29 @@
 ();%0A
-%09%09%7D%0A%09%7D%0A%09%0A%09
+        %7D%0A    %7D%0A%0A    
 publ
@@ -694,18 +694,24 @@
 ice() %7B%0A
-%09%09
+        
 PrintSer
@@ -762,21 +762,25 @@
 ices();%0A
-%09%09%0A%09%09
+%0A        
 for (Pri
@@ -811,19 +811,28 @@
 ices) %7B%0A
-%09%09%09
+            
 System.o
@@ -862,25 +862,35 @@
 ame());%0A
-%09%09%7D%0A%09%09%0A%09%09
+        %7D%0A%0A        
 return s
@@ -905,14 +905,19 @@
 0%5D;%0A
-%09%7D%0A%09%0A%09
+    %7D%0A%0A    
 @Ove
@@ -922,17 +922,20 @@
 verride%0A
-%09
+    
 public i
@@ -1006,18 +1006,24 @@
 ption %7B%0A
-%09%09
+        
 if (page
@@ -1034,11 +1034,20 @@
 ) %7B%0A
-%09%09%09
+            
 retu
@@ -1067,17 +1067,27 @@
 GE;%0A
-%09%09%7D%0A%09%09%0A%09%09
+        %7D%0A%0A        
 Grap
@@ -1115,13 +1115,20 @@
 s2D)
+ 
 g;%0A
-%09%09
+        
 g2d.
@@ -1178,21 +1178,25 @@
 leY());%0A
-%09%09%0A%09%09
+%0A        
 g.setFon
@@ -1235,18 +1235,24 @@
 , 12));%0A
-%09%09
+        
 g.drawSt
@@ -1302,13 +1302,17 @@
 0);%0A
-%09%09%0A%09%09
+%0A        
 retu
@@ -1331,12 +1331,19 @@
 TS;%0A
-%09%7D%0A%09
+    %7D%0A%0A    
 publ
@@ -1375,16 +1375,17 @@
 g...
+ 
 args) %7B%0A
 %09%09Sy
@@ -1380,18 +1380,24 @@
 args) %7B%0A
-%09%09
+        
 System.o
@@ -1447,10 +1447,16 @@
 );%0A%0A
-%09%09
+        
 new 
@@ -1489,9 +1489,12 @@
 ();%0A
-%09
+    
 %7D%0A%7D%0A

Update HelloPrintingWithoutDialog.java