Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > convert a html-page into a tiff-file

Reply
Thread Tools

convert a html-page into a tiff-file

 
 
Atze
Guest
Posts: n/a
 
      11-13-2003
Hi,
I try to find a way to convert a html-page (contains only text in tables) into a
tiff-file, using SUNs
Java Advanced Imaging - JAI.
First I use JEditorPane named "HTMLEdit" in the class "HTMLViewer" to generate
a Java-window showing the html-file.
Then I try to put these components into a graphic-object which is used then to
build the tiff-file.



public void makeTiff() throws ServletException, IOException {

try {
HTMLViewer HTMLView = new HTMLViewer();
HTMLView.addNotify();
BufferedImage bImage = new BufferedImage(1024,768,
BufferedImage.TYPE_BYTE_BINARY);
Graphics graphOut = bImage.getGraphics();
HTMLView.paintAll(graphOut);
PlanarImage planarImage = PlanarImage.wrapRenderedImage(bImage);
ParameterBlock pb = new ParameterBlock();
pb.addSource(planarImage);
TIFFEncodeParam encodeParam = new TIFFEncodeParam();
encodeParam.setCompression(TIFFEncodeParam.COMPRES SION_GROUP4);
OutputStream os = new FileOutputStream("html_picture.tiff");
pb.add(os);
pb.add("TIFF");
pb.add(encodeParam);
JAI.create("encode",pb);
os.close();
}
catch(Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
}

public class HTMLViewer extends JFrame {

public JEditorPane HTMLEdit = new JEditorPane();
public HTMLViewer(){
super("HTMLViewer");
setSize(1024,76;
Container cp = getContentPane();
String s = null;
try{
s = "file:./want_to_be_tiff.html";
URL fileURL = new URL(s);
HTMLEdit.setPage(s);
HTMLEdit.setEditable(false);
cp.add(HTMLEdit);
setVisible(true);
}
catch(Exception e){
e.printStackTrace();
}
}

The problem is that the generated tiff is empty.
Using
HTMLView.printAll(graphOut);
instead of
HTMLView.paintAll(graphOut);
generates a better result, the tiff contains the border of the
HTMLViewer-window, but not it's html-content.

Has someone an idea?

best regards
Atze



 
Reply With Quote
 
 
 
 
Atze
Guest
Posts: n/a
 
      11-14-2003

"Atze" <(E-Mail Removed)> wrote in message
news:bp0e7r$kk7$01$(E-Mail Removed)-online.com...
> ...
> public void makeTiff() throws ServletException, IOException {
>
> try {
> HTMLViewer HTMLView = new HTMLViewer();
> HTMLView.addNotify();
> BufferedImage bImage = new BufferedImage(1024,768,
> BufferedImage.TYPE_BYTE_BINARY);
> Graphics graphOut = bImage.getGraphics();
>
> HTMLView.paintAll(graphOut);
> ...


Better is:

public void makeTiff() throws ServletException, IOException {

try {
HTMLViewer HTMLView = new HTMLViewer();
HTMLView.addNotify();

Thread.sleep(5000);

BufferedImage bImage = new BufferedImage(1024,768,
BufferedImage.TYPE_BYTE_BINARY);
Graphics graphOut = bImage.getGraphics();

HTMLView.paintAll(graphOut);

Durch die Einführung einer kleinen Programmpause hat das JEditorPane mehr Zeit,
das html-Zeugs richtig aufzuarbeiten.
Erst wenn das fertig ist, darf das Grafik-Objekt daraus erzeugt werden, sonst
fehlt die Hälfte.

Because of the Thread.sleep(5000) the JEditorPane has more time to create the
html-page.
The creation of the graphics-object must start after the generating of the html,
otherwise it doesn't contain the whole page.

Gruß Atze



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IsNumeric: Convert.ToInt32 vs. Convert.ToInt64 sck10 ASP .Net 4 09-03-2006 09:40 PM
To convert to J2SE 6 or not to convert, that is the question... Jaap Java 4 07-10-2006 09:03 AM
convert list of strings to set of regexes; convert list of strings to trie Klaus Neuner Python 7 07-26-2004 07:25 AM
Tools to extract data from SQL database and convert it into XML & insert XML data into SQL databases Harry Zoroc XML 1 07-12-2004 10:10 PM
Do I need to Convert with Convert.ToInt32(session("myNumber")) ? Andreas Klemt ASP .Net 1 07-23-2003 02:59 PM



Advertisments