Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To build on two of the answers above:</p> <p>Rendering the HTML in Java then saving to an image - A few Java based HTML renders exist, all with different sets of drawbacks. The most common is the one <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/html/HTMLEditorKit.html" rel="noreferrer">built in</a>. This is quite simple and can only render fairly basic HTML. The most intresting I know of is <a href="http://code.google.com/p/flying-saucer/" rel="noreferrer">The Flying Saucer Project</a>. This can render fairly complex XHTML but you will have to convert HTML before you can use it (<a href="http://jtidy.sourceforge.net/" rel="noreferrer">JTindy</a> may be able to help here). Taking a Swing component and creating a image is fairly simple, you just pass an <a href="http://java.sun.com/javase/6/docs/api/java/awt/image/BufferedImage.html" rel="noreferrer"><code>BufferedImage</code></a>s <a href="http://java.sun.com/javase/6/docs/api/java/awt/image/BufferedImage.html#createGraphics%28%29" rel="noreferrer">graphics</a> object and pass it to the Swing components <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#paint(java.awt.Graphics)" rel="noreferrer">paint</a> method. Then splat that out with <a href="http://java.sun.com/javase/6/docs/api/javax/imageio/ImageIO.html" rel="noreferrer">ImageIO</a>.<br> A big advantage to this would be that the renderer would be headless. The disadvantage is that it would not be a perfect rendering and it would lack any plugins.</p> <p>The second option requires you to start a web browser, work out where it is and then take a screen shot. Optionally you may also wish to strip out all the Firefox/IE/Opera/etc menus leaving you with just image. To get the dimensions of the web browser the simplest option would be to start it full screen. The other option would be to use something like JDICs <a href="https://jdic.dev.java.net/nonav/documentation/javadoc/jdic/org/jdesktop/jdic/browser" rel="noreferrer">browser</a> component to include it as part of the Java application. It would then be able to specify where the HTML is being rendered on screen and then simply use <a href="http://java.sun.com/javase/6/docs/api/java/awt/Robot.html" rel="noreferrer">Robot</a> to create a screen shot of that area.<br> The big advantage to this is that it will give a perfect rendering (for a given browser). The two disadvantages is that it would require native code (or at least using a native component) and it could not be headless¹.</p> <p>1) You could use a virtual frame buffer. But that is outside Java.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload