For a project I needed to work out a way to make thumbnails/screenshots of HTML files for some Java code I was working on. From my research, I found a nice project called the The Flying Saucer Project which has an XML/XHTML/CSS 2.1 renderer which works for what I needed for my project. Taking the HTML files and using JTidy to make them in to XHTML the renderer could output an image file for me. You are also able to use the renderer to make PDFs and SVG files. I wanted to take the small part of my code that was written in Java and port it over to Groovy. As I’m still learning Groovy I’m sure there is way to make this code better and I would love some feedback!

Here is the code,

Here is the output from the code,

www.128bitstudios.com

www.128bitstudios.com

en.wikipedia.org

en.wikipedia.org

misplaced-packets.net

misplaced-packets.net

stackoverflow.com

stackoverflow.com

As you can see the output isn’t perfect but if you are just making thumbnails it should be ok. It has issues when it comes to java script which on some sites are used for layout. If you have a site/HTML file that just uses HTML and CSS the output should be good. I would love someone that is better acquainted with Groovy to over look this for way to make the code more ‘groovify’.

Open for questions, comments, or any way to improve this!