- We design and build extraordinary applications for companies looking to make the next great idea a reality.
- learn more
How to do Page Preview in Java with Embedded HTML Rendering
He who doesn't look ahead remains behind. -- Mexican Proverb
One Ajax technique you see quite a bit of lately is the page preview. This is where the html page is rendered as an image so that you can cast a skeptical eye on a tiny version instead of navigating to a lame page. The tech social bookmarking site dzone features an excellent version of this.
So, how do you get a screenshot of a web page from within a Java app using open source? Back in 2004, Joshua Marinacci wrote a very useful article on just this sort of technology, entitled Java Sketchbook: The HTML Renderer Shootout, Part 1. The article is a bit out of date, but at least one of the tools -- JRex -- is still around and kicking.
All of these tools are intended to be used as components for providing interactive HTML rendering and browsing for desktop applications, but just because it is intended for one thing does not mean you can't use it for another. In fact, you can use this technique of using Swing components to render images with some of the following XHTML/CSS rendering engines.
- JRex - the oldest of the contenders. Not pure Java; uses the Mozilla Gecko Runtime Environment (GRE), a minimal HTML rendering engine.
- Flying Saucer - pure Java renderer with support CSS 2.1, but not Javascript.
- Cobra HTML Toolkit - A pure Java HTML 4 parser and renderer. Supports Javascript and CSS2. The Warrior HTML browser is based on this toolkit.
JRex with Gecko will give you the best and most robust results. For legacy HTML, you many want to use JTidy to clean it up into XHTML before passing it into the last two renderers.
The only thing that worries me is that with Javascript enabled, one could have the same sort of exploits we see in regular browsers, only now targeted at servers that use these embedded rendering engines. Since something like this would run unattended for days and weeks, there's a real concern that things could get out of control. There are ways of sandboxing and locking down, and that's something definitely worth considering.
Topics: Ajax Development
Comments: 1 so far
Leave a comment
About Pathfinder
Recent
- Project Website Part 4: Drag and Drop in jQuery
- The App Store, iPhone, and You
- Multiple Column Sorting with Drag and Drop using Scriptaculous
- Five jQuery plugins that are a joy to use
- Visualizing Your Database Schema Entirely in Rails
- jQuery plugins: Five tips for separating the good from the bad and the ugly
- Resolved: Should schema.rb be included in your source control?
- Flash 10 - FileReference Runtime Access
- Papervision3d 2.0 (Great White) in Flex 3 (Part I)
- MetaWidget - Convention over Configuration UI
Archives
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006



If your title has “How To” in it, your “How To” should provide a code samples.
Comment by Mark, Wednesday, December 20, 2006 @ 2:34 am