convert a html-page into a tiff-file

A

Atze

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.COMPRESSION_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,768);
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
 
A

Atze

Atze said:
...
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top