package servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.awt.print.*;
import java.awt.Graphics;

public class print extends HttpServlet {
public void doGet(
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException, java.io.IOException {
try {
PrinterJob pjob = PrinterJob.getPrinterJob();
pjob.setJobName("my test print");
pjob.setCopies(1);
pjob.setPrintable(new Printable() {
public int print(Graphics pg, PageFormat pf, int pageNum) {
if (pageNum > 0)
return Printable.NO_SUCH_PAGE;
else
return Printable.PAGE_EXISTS;
}
});

System.out.println("asking for printer");


if (pjob.printDialog() == false) {
System.out.println("print dialog is false, didn't choose printer");

return;
} else {
System.out.println("choose printer");
pjob.print();
System.out.println("after print job");
}

} catch (PrinterException e) {
System.out.println("ERROR: " + e.toString());
}
return;
}
} 