convert a html-page into a tiff-file

Discussion in 'Java' started by Atze, Nov 13, 2003.

  1. Atze

    Atze Guest

    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
    Atze, Nov 13, 2003
    #1
    1. Advertising

  2. Atze

    Atze Guest

    I solved the problem

    "Atze" <> wrote in message
    news:bp0e7r$kk7$01$-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
    Atze, Nov 14, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ather Ali Shaikh
    Replies:
    1
    Views:
    2,829
    ASP.Confused
    Jul 23, 2004
  2. cyril
    Replies:
    1
    Views:
    789
    cyril
    Sep 8, 2003
  3. Armin Gajda

    JAI - How to convert PNG to TIFF

    Armin Gajda, Mar 6, 2006, in forum: Java
    Replies:
    2
    Views:
    7,875
    Thomas Weidenfeller
    Mar 6, 2006
  4. ifiaz
    Replies:
    1
    Views:
    919
    Martien Verbruggen
    Nov 19, 2003
Loading...

Share This Page