Class ImageRenderer
ImageRenderer supports rendering of XHTML documents to image formats, writing out the generated image to an output stream
or a file in a given image format. There are two static utility methods, one for rendering
a URL
, renderToImage(String, String, int)
and one
for rendering a File
, renderToImage(File, String, int)
You can use this utility from the command line by passing in the URL or file location as first parameter, and output file path as second parameter:
java -cp %classpath% org.xhtmlrenderer.simple.ImageRenderer <url> <img>
If the second parameters is not provided, a PNG-format image will be created in the same directory as the source (if source is a file) or as a temp file in the standard temp directory; the output file name will be printed out in either case.
Image width must always be supplied; height is determined automatically.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImage
renderToImage
(File xhtmlFile, String path, int width) Renders the XML file as an image file at the target location.static BufferedImage
renderToImage
(String url, String path, int width) Renders the XML file at the given URL as an image file at the target location.static BufferedImage
renderToImage
(URL xhtmlUrl, String path, int width)
-
Constructor Details
-
ImageRenderer
public ImageRenderer()
-
-
Method Details
-
renderToImage
Renders the XML file at the given URL as an image file at the target location. Width must be provided, height is determined automatically based on content and CSS.- Parameters:
url
- url for the XML file to renderpath
- path to the PDF file to createwidth
- Width in pixels to which the document should be constrained.- Throws:
IOException
- if the input URL, or output path location is invalid
-
renderToImage
public static BufferedImage renderToImage(File xhtmlFile, String path, int width) throws IOException Renders the XML file as an image file at the target location. Width must be provided, height is determined automatically based on content and CSS.- Parameters:
xhtmlFile
- XML file to renderpath
- path to the image file to createwidth
- Width in pixels to which the document should be constrained.- Throws:
IOException
- if the input URL, or output path location is invalid
-
renderToImage
- Throws:
IOException
-