Solved

Send Data Stream to Printer

Posted on 2003-11-10
11
411 Views
Last Modified: 2010-03-31
Servlet generates PDF data stream and returns the stream to applet. How to send the stream to printer so that it can be directly printed? Thanks..
0
Comment
Question by:kasimchen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +1
11 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9720446
Doubt you can. What is done with the data is handled by the browser, the servlet really has nothing to do with it.
0
 

Author Comment

by:kasimchen
ID: 9720498
sorry.. i didn't mention it clearly.
I mean to send the stream to printer from applet side.
What is the Java API to do this action?
0
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 200 total points
ID: 9720526
As far as I know, all printing in a browser (where the applet is running) is handled by the browser. In other words, I don't believe that you can print the stream content to a printer using the printing support in Java from inside  applet.

Also, I haven't heard of a printer that is directly PDF compatible, which means that even if you could open a network stream directly to a printer, you wouldn't be able to print it without transforming the PDF to a printer specific language. Of course, translating PDF to PostScript is rather simple, but not to e.g. PCL.

Good luck,

\t
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 92

Expert Comment

by:objects
ID: 9720529
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9720894
Theoretically, you could encode it as PostScript in the applet and send it to a printer, using new FileOutputStream("lpt1");
The applet would have to be signed or the security policy altered.
0
 
LVL 92

Expert Comment

by:objects
ID: 9726460
Far easier to use Java's Print API.
0
 

Author Comment

by:kasimchen
ID: 9728144
I tried the method offered by CEHJ, but the applet hangs (not responding) when I execute printing. It stucks at the line fos.write(data); and does not throw any exception. I had the applet signed already.
        try {
            FileInputStream fis =  new FileInputStream("c:/out.ps");
            FileOutputStream fos = new FileOutputStream("LPT1");
            int data;
            while ((data=fis.read()) != -1)
                fos.write(data);
            fos.close();
        }
        catch (Throwable ex) {
            System.err.println("*** exception ***");
        }
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 9728810
Just making sure, is there a printer connected to LPT1: ? Also, I am not sure that LPT1: behaves like a file on Windows. It does (if supported) on *nix platforms. You could try (if supported by the printer) to access the printer over TCP/IP and switching the implementation to use an outputstream acquired from a Socket.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9730900
>>Also, I am not sure that LPT1: behaves like a file on Windows.

Yes, it does. But the printer will have to be set up to print like this, as it's a glimpse back into the sepia-tinted world of DOS printing.
0
 

Author Comment

by:kasimchen
ID: 9732181
No, I use network printer.
It seems that Java's Print API doesn't help much. Maybe it's better and more efficient to show the PDF in browser and let user prints from Acrobat Reader.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9733079
Yes, if you set the contentType to pdf, if there's a browser plugin, it should activate in-place
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Certificat to iSeries KeyStore 1 30
by zero exception 10 83
Need Help! Getting a syntax error and don't understand why 3 55
JVM error from eclipse 1 26
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question