Printing from Applets

Printing from Applets

I am trying to construct an applet that accepts data from the user and performs several calculations on that data.I would like to give the capability to print out the results of the calculation in a form. The template for the form will reside on the applet’s server. Is there any way to take the information given by the user and the results of the calculation and insert them into the form, and then print the form to the users local printer? I was thinking that I could implement a client/server to do this but am not quite sure about this.

Java does not provide any support for printing at this point. Printer access may be provided in future releases of Java but there is no standard platform-independent way to print from Java applets or Java applications today.

This probably has as much to do with the multitude of printing software and printers out there as it does with the many ways operating systems handle printing. If Java were to support one, it would have to support all of them in order to remain truly cross-platform.

Even if there were a way to print from Java, applets probably wouldn’t be allowed to print simply because applet access to local devices and files is strictly forbidden for security reasons. Imagine a malicious applet that started printing garbage to the user’s local printer as soon as it was loaded from the Net. It might steal fonts out of your printer, interfere with the existing print jobs, or print tons and tons of annoying advertisements without your knowing where they came from.

See also  5 Tips for Working With an Onsite Interpreter

You might be able to create a standalone Java application for printing to a particular device on a given operating system, but it’s sure to be platform dependent. For example, if there’s a way to get to the parallel or serial port on your system through a file name, say /dev/ttya on UNIX systems, or lpt1 on wintel systems, you can certainly open a connection to the printer through the parallel or serial port file name and feed the text or postscript data to it, but there is no way for the app to know if it’s talking to a printer or to a modem. Here’s how that might look in Java:

        import*;        PrintStream printer = new PrintStream(new FileOutputStream(“/dev/ttya”));        for (int i = 0; i < lineCount; i++)                 printer.println(line[i]);


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist