Servlet / jsp print dialog

I want to display a 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 unable to display the print dialog in servlet / jsp.

0


source to share


2 answers


You need to be aware that client code is not being executed here. This is a server.



You will need to make a javascript function to work.

+1


source


I would call it window.print();

in javascript. Try this below.



<html>
<body>

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

</html>

      

0


source







All Articles