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.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Renders a file or URL to an image file.private static BufferedImage
renderImageToOutput
(String url, String path, int width) Renders a document at a given URL and writes it out using the FSImageWriter provided (e.g.static BufferedImage
renderToImage
(File inFile, String path, int width) Renders the XML file as an image file at the target location.static BufferedImage
renderToImage
(File inFile, String path, int width, int height) 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
(String url, String path, int width, int height) Renders the XML file at the given URL as an image file at the target location.private static void
prints out usage information, with optional error message
-
Field Details
-
DEFAULT_WIDTH
public static final int DEFAULT_WIDTH- See Also:
-
-
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(String url, String path, int width, int height) throws IOException Renders the XML file at the given URL as an image file at the target location.- 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.height
- Height in pixels to which the document should be constrained.- Throws:
IOException
- if the input URL, or output path location is invalid
-
renderToImage
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:
inFile
- 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
public static BufferedImage renderToImage(File inFile, String path, int width, int height) 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:
inFile
- XML file to renderpath
- path to the image file to createwidth
- Width in pixels to which the document should be constrained.height
- Height in pixels to which the document should be constrained.- Throws:
IOException
- if the input URL, or output path location is invalid
-
renderImageToOutput
private static BufferedImage renderImageToOutput(String url, String path, int width) throws IOException Renders a document at a given URL and writes it out using the FSImageWriter provided (e.g. to a file or output stream).- Throws:
IOException
-
main
Renders a file or URL to an image file. Command line use: first argument is URL or file path, second argument is path to image file to generate.- Parameters:
args
- see desc- Throws:
IOException
- if source could not be read, or if image path is invalid
-
usage
prints out usage information, with optional error message
-