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.

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]);

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS