Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Printing a HTML Document

Thread view: 
Oitne.Inside@gmail.com - 05 Dec 2007 11:21 GMT
Hi there,

We have a little problem. We just started coding in Java and now we
need to load a html document from a webserver and print it out. We
figgured out this can be done using HTML component, but when we
execute this code, the pages stay blank. My guess is that we aren't
loading the page inside the HTML Component. Anyone got an idea???

Our code:

HTMLDocument x = new HTMLDocument();
URL u;
InputStream is = null;
DataInputStream dis;
u = new URL("http://www.mysite.com/htmlfile.php");
x.setBase(u);
dr.print(x);
rossum - 05 Dec 2007 13:26 GMT
>Hi there,
>
[quoted text clipped - 13 lines]
>x.setBase(u);
>dr.print(x);

Can you print a very simple HTML document?

<html>
 <head>
  <title>Hello World!</title>
 </head>
 <body>
  <p>Hello World!</p>
 </body>
</html>

from the local hard disc?

HTMLDocument x = new HTMLDocument();
URL u;
InputStream is = null;
DataInputStream dis;
u = new URL("file://localhost/C:/temp/helloworld.html");
x.setBase(u);
dr.print(x);

Once you get that working then add complications to the source of the
HTML file and to the HTML file itself.

rossum
Michael Jung - 05 Dec 2007 22:26 GMT
> We have a little problem. We just started coding in Java and now we
> need to load a html document from a webserver and print it out. We
> figgured out this can be done using HTML component, but when we
> execute this code, the pages stay blank. My guess is that we aren't
> loading the page inside the HTML Component. Anyone got an idea???

> HTMLDocument x = new HTMLDocument();
> URL u;
[quoted text clipped - 3 lines]
> x.setBase(u);
> dr.print(x);

What are "is" and "dis" good for?  What's a"dr"?  In general
HTMLDocument don't render by themselves.  You have to lay them out
somewhere.  Remember HTML can be rendered in narrow or wide screens.

Michael
Oitne.Inside@gmail.com - 06 Dec 2007 07:58 GMT
> What are "is" and "dis" good for?  What's a"dr"?  In general
> HTMLDocument don't render by themselves.  You have to lay them out
> somewhere.  RememberHTMLcan be rendered in narrow or wide screens.

So we have to render the code before sending it to the printer. Can
you tell us how we render it?
Lew - 06 Dec 2007 08:01 GMT
Michael Jung wrote:
>> What are "is" and "dis" good for?  What's a"dr"?  In general
>> HTMLDocument don't render by themselves.  You have to lay them out
>> somewhere.  RememberHTMLcan be rendered in narrow or wide screens.

> So we have to render the code before sending it to the printer. Can
> you tell us how we render it?

Now, to be fair, you should really answer Michael's questions, then ask your own.

Signature

Lew

Andrew Thompson - 06 Dec 2007 08:37 GMT
>Michael Jung wrote:
>>> What are "is" and "dis" good for?  What's a"dr"?  In general
[quoted text clipped - 5 lines]
>
>Now, to be fair, ..

Fair?  I hate that word.  To me it means 'light coloring'.

I would say OTOH, that is is both sensible and constructive
to answer the questions of people trying to help.

>..you should really answer Michael's questions, then ask your own.

One good way to answer most of those questions,
would be to prepare an SSCCE* of the current code.

* <http://www.physci.org/codes/sscce.html>

Signature

Andrew Thompson
http://www.physci.org/

Lew - 06 Dec 2007 13:40 GMT
Lew wrote:
>> Now, to be fair, ..

> Fair?  I hate that word.  To me it means 'light coloring'.

That's like saying you don't use the word "good" as a moral judgment because
it (also!) means "an item of commerce".

Anyway, "fair" means "between the baselines", thus allowing the runner to
attempt to reach first and be safe, while the fielders attempt to throw him out.

If you want to test a ferris wheel, give it a fair trial.

<http://en.wiktionary.org/wiki/fair>

Signature

Lew

Andrew Thompson - 06 Dec 2007 14:13 GMT
...
>If you want to test a ferris wheel, give it a fair trial.

Yeah, yeah.. just allowing some of my 'petty (word)
prejudices' show through.  ;-)

( I prefer the roller-coaster, ..or dodgem' cars, BTW ;)

Signature

Andrew Thompson
http://www.physci.org/

Lew - 06 Dec 2007 14:16 GMT
> ...
>> If you want to test a ferris wheel, give it a fair trial.
[quoted text clipped - 3 lines]
>
> ( I prefer the roller-coaster, ..or dodgem' cars, BTW ;)

You can try those at the fair, too.  (In the U.S., the latter ride is called
"bumper cars".  It looks like one term focuses on the defense, the other on
the offense.)

Signature

Lew

Andrew Thompson - 06 Dec 2007 14:23 GMT
>> ...
>>> If you want to test a ferris wheel, give it a fair trial.
[quoted text clipped - 5 lines]
>"bumper cars".  It looks like one term focuses on the defense, the other on
>the offense.)

Well actually ..now you mention it (wicked grin) my strategy
was never the 'dodge' so much as the 'strategic bump'.  ;-)

Signature

Andrew Thompson
http://www.physci.org/

Roedy Green - 06 Dec 2007 09:46 GMT
> HTML Component. Anyone got an idea???

A platform dependent way would be use exec to feed the document to a
browser  with a print command.

See http://mindprod.com/jgloss/exec.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Oitne.Inside@gmail.com - 06 Dec 2007 10:43 GMT
Andrew, could you ask your question more specific? Then I will be able
to answer it, and maybe you could help us out here.
Andrew Thompson - 06 Dec 2007 11:33 GMT
>Andrew, could you ask your question more specific?

I felt Michael's questions were fairly specific, but ultimatety,
"code* answers a thousand questions".

* Specifically, code that is an SSCCE.

>...Then I will be able
>to answer it, and maybe you could help us out here.

What did you *not* understand about Michael's questions?

Note there is only so much 'guesswork' that people are prepared
to do on your behalf - the rest needs to be filled in
(stated/written/explained), specifically, by you.

Have you *read* the SSCCE document yet?  If there was anything
in it that was incomprehensible (gobble-de-gook, nonsense, ..) I
would like to be told that (since I created the document, and it is
intended to help programmers).

Signature

Andrew Thompson
http://www.physci.org/

Oitne.Inside@gmail.com - 06 Dec 2007 10:50 GMT
Got it fixed :

import java.net.*;
import java.io.*;
import javax.swing.*;
public class FileDownload {
    public static void main(String[] args){
        JEditorPane output = new JEditorPane();
        output.setContentType( "text/html" );
        output.setEditable( false );
        try{
        output.setPage("mysite.com/file.php");
        output.print();
        }catch(Exception e){System.err.print(e);}

    }
}
Andrew Thompson - 06 Dec 2007 11:36 GMT
>Got it fixed :

Good work!  Glad you got it sorted, and thanks for having the
common sense to report it back to us.  :-)

..But I wish I'd noticed this post before I 'got on my high horse',
and wasted *that* bit of bandwidth!  ;-)

Signature

Andrew Thompson
http://www.physci.org/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.