views:

530

answers:

3

I want to display print dialog in servlet/jsp. Below is my code:

DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet () ; PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras); PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); PrintService service = javax.print.ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);

if (service != null) { DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(decodedImageData, flavor, null); job.print(doc, null); }

It works well in standalone application. However, I am not able to display print dialog in servlet/jsp. Can someone help me please?

Thanks a lot.

+1  A: 

You need to be aware that it is not the client that is executing your code here. It's the server.

You'll have to make a javascript function for that to work.

Loki
A: 

Thank you, Loki.

I decided to use Applet to print it. It has been resolved.

A: 

I would call window.print(); in javascript. Try it below.

<html>
<body>

<a href="javascript:print()">Print</a>
</body>

</html>
Paul Whelan