Printing in Java...

I wrote an applet to locate a printer and print the document.

The document which i sent to the printer is the one which i created programatically using the Book Class and Pageable.

Now what i want is, whether the applet should be able to stream data from the server and print that to the printer.

My server is not java servlets.

Its in .NET; ASP.NET and C#

Can this be possible?.

Example code will be appreciated.

Thank You for ur help.

[485 byte] By [santhoshymaa] at [2007-10-3 2:50:14]
# 1
> My server is not java servlets.> Its in .NET; ASP.NET and C#Why should that matter? Connect and get the data. How the data is obtained is irrelevant.> Can this be possible?.Sure. UrlConnection and you're done.
CeciNEstPasUnProgrammeura at 2007-7-14 20:39:03 > top of Java-index,Java Essentials,Java Programming...
# 2
I will repeat my post [url= http://forum.java.sun.com/thread.jspa?threadID=760602]here[/url] about the networking tutorial if you like?
mlka at 2007-7-14 20:39:03 > top of Java-index,Java Essentials,Java Programming...
# 3
yes i'm able to establish a URLConnection to the server but what i'm getting is hmtl contents not the data which the outputstream had sent
santhoshymaa at 2007-7-14 20:39:03 > top of Java-index,Java Essentials,Java Programming...
# 4

> yes i'm able to establish a URLConnection to the

> server but what i'm getting is hmtl contents not the

> data which the outputstream had sent

Then you're obviously connecting to the wrong thing. Or it's the correct thing and it delivers something else than you assumed it would.

CeciNEstPasUnProgrammeura at 2007-7-14 20:39:03 > top of Java-index,Java Essentials,Java Programming...
# 5

This is my applet code for URL Connection.

URL currentPage=getCodeBase();

String protocol = currentPage.getProtocol();

String host=currentPage.getHost();

int port=currentPage.getPort();

String urlSuffix="/PrintAppletCSharp/Default.aspx";

System.out.println("currentPage : " + currentPage + "\nprotocol : " + protocol + "\nhost : " + host + "\nport : " + port);

try {

URL dataUrl=new URL(protocol,host,port);

URLConnection connection=dataUrl.openConnection();

connection.setUseCaches(false);

connection.setRequestProperty("header", "value");

System.out.println("Got a connection");

BufferedReader in=new BufferedReader(new InputStreamReader(connection.getInputStream()));

System.out.println("After Getting a connection");

String line="";

while(line!=null)

{

line=in.readLine();

if(line!=null)

fromServer+=line + "\n";

System.out.println("Line " + line);

}

repaint();

} catch (Exception ex) {

ex.printStackTrace();

}

santhoshymaa at 2007-7-14 20:39:03 > top of Java-index,Java Essentials,Java Programming...
# 6
http://forum.java.sun.com/help.jspa?sec=formatting
CeciNEstPasUnProgrammeura at 2007-7-14 20:39:03 > top of Java-index,Java Essentials,Java Programming...
# 7

URL currentPage=getCodeBase();

String protocol = currentPage.getProtocol();

String host=currentPage.getHost();

int port=currentPage.getPort();

String urlSuffix="/PrintAppletCSharp/Default.aspx";

System.out.println("currentPage : " + currentPage + "\nprotocol : " + protocol + "\nhost : " + host + "\nport : " + port);

try {

URL dataUrl=new URL(protocol,host,port);

URLConnection connection=dataUrl.openConnection();

connection.setUseCaches(false);

connection.setRequestProperty("header", "value");

System.out.println("Got a connection");

BufferedReader in=new BufferedReader(new InputStreamReader(connection.getInputStream()));

System.out.println("After Getting a connection");

String line="";

while(line!=null)

{

line=in.readLine();

if(line!=null)

fromServer+=line + "\n";

System.out.println("Line " + line);

}

repaint();

} catch (Exception ex) {

ex.printStackTrace();

}

santhoshymaa at 2007-7-14 20:39:03 > top of Java-index,Java Essentials,Java Programming...
# 8
And now see Reply 4.Also, if you're expecting data: why do you use a Reader?
CeciNEstPasUnProgrammeura at 2007-7-14 20:39:03 > top of Java-index,Java Essentials,Java Programming...
# 9
then what else? other than a reader?think u know the answer then please explain it more clearly.
santhoshymaa at 2007-7-14 20:39:03 > top of Java-index,Java Essentials,Java Programming...
# 10

> then what else? other than a reader?

>

> think u know the answer then please explain it more

> clearly.

I probably know the answer, but I don't know the question. You said you expect "data". All I know is that "data" is "not HTML". Assuming that it's also not other text, a Reader is the wrong tool. The correct one I don't know because I can't read your mind.

CeciNEstPasUnProgrammeura at 2007-7-14 20:39:03 > top of Java-index,Java Essentials,Java Programming...
# 11

ok then let me make it more clear.

i want the server to send a data "Programmer" for example to the applet

When i opened a connection as in the source code..what i got was the complete HTML of that page containing the applet.

But i want the data "Programmer" to be read by client

The server is C# in .NET.

santhoshymaa at 2007-7-14 20:39:03 > top of Java-index,Java Essentials,Java Programming...