Dell
Dell

Reputation:

Print Dialog in servlet/jsp

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 a standalone application. However, I am not able to display print dialog in servlet/jsp.

Upvotes: 0

Views: 2038

Answers (2)

Paul Whelan
Paul Whelan

Reputation: 16799

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

<html>
<body>

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

</html>

Upvotes: 0

Loki
Loki

Reputation: 30960

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.

Upvotes: 1

Related Questions