开发者

Headless HTML rendering to image on CentOS 5.4

I have a project requirement to render HTML and capture the rendered image as a file on a headless CentOS 5.4 server. My specific requirements are:

1) Input will be a URL to the page to render (or file:// URL to a local HTML file), output will be an image file containing the rendered image of the page

2) CSS must be supported by the renderer up to CSS level-1

3) Static images in the page must be displayed properly in the rendered image, including any transparent color in .GIF or .PNG files

4) Must be able to run on a headless CentOS 5.4 server.

5) Solution must not depend on any product or component that is not free for commercial use

I do not need to do anything with the page other than get the screen capture and save it to an image. The hard part seems to be doing this in a headless environment. Some of the solutions that I've seen discussed need a display in order to work.

Any suggestions?

Thanks in advance, Jim

SOLUTION: I ended up using the Standard Widget Toolkit library (www.eclipse.org/swt) for its embedded browser capabilities. This allowed me to programmatically open a window with a browser control in it, render the page, then capture the content of the window to an image file (usually a PNG). The only downside to this approach that cannot be avoided is a "flicker" when the window must be made visible for a moment in order to do the screen capture. I can live with it. The rest was just code to initialize the SWT objects that obtain system resources, a listener to check for a successful completion of the page load, and some code to clean up a hung connection (when the page load never completes for whatever reason).

I got a teammate to play around with x开发者_JAVA技巧vfb (X virtual framebuffer) on CentOS Linux. The initial tests appear to work, so it looks like the advice from the poster below (who said to try xvfb) may be a viable solution for the headless server part of my issue.


You can start a virtual X-windows environment using xvfb . You can now start a regular browser to render the page and use a screencapture utility to capture the content of the window. It is not pretty, but straghtforward to do.

WebKit is open-source and embeddable, maybe you can use this in a small native app to render on a canvas and save it to disk?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜