0

We have a java-web application hosted on amazon ec2(ubuntu).

I'm unable to redirect my printing to the local default printers. In fact when i try to get a list of printers visible using the below code The only printer service that is listed on there is "PDF"

javax.print.PrintService[] service = (javax.print.PrintService[]) PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.AUTOSENSE, null)
        javax.print.PrintService service= null;
        for(javax.print.PrintService service1 : services){
            service = service1;
            System.out.println(service1.getName());
        }

Any suggestions/ tips is really appreciated.

user1751510
  • 291
  • 2
  • 14
  • It's a networking question, you need to connect your local network and VPC. Probably you need VPN, or you can looks at https://aws.amazon.com/directconnect/ – Tarlog Apr 21 '17 at 19:40
  • Tarlog, thanks for your reply, i just want to make it clear that, its just not connecting to our local system, we want it to be possible to print to anyone's local printers, when they load our site on the browser. – user1751510 Apr 21 '17 at 19:51
  • 1
    If you want people to be able to print from their browser you should just give them a downloadable file and let them use the browser's built in printing functionality. You won't be able to access their hardware from your web app server. – RaceYouAnytime Apr 21 '17 at 19:53
  • I will try that thank you! – user1751510 Apr 21 '17 at 20:24
  • You cannot use Java for this, since it's serverside. But you can use Javascript window.print. See https://www.w3schools.com/jsref/met_win_print.asp – Tarlog Apr 21 '17 at 22:00

1 Answers1

0

You cannot do it in Java, since it's running on the server side, but you can do it in JavaScript in the browser.

Given that you want to print the whole web page, add HTML button "Print" that will call to JavaScript: window.print().

Another option can be opening a pop-up, with window.print() called after the page is loaded. This can be useful, if you want to modify page's content before calling to print. For example removing the 'Print' button.

Tarlog
  • 10,024
  • 2
  • 43
  • 67