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
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