Check if collection isn’t null (images extraction is supported for the document);
Iterate through the collection and save image contents to the file.
The following example shows how to save images to files:
// Create an instance of Parser class
try(Parserparser=newParser(Constants.SampleZip)){// Extract images from document
Iterable<PageImageArea>images=parser.getImages();// Check if images extraction is supported
if(images==null){System.out.println("Page images extraction isn't supported");return;}// Create the options to save images in PNG format
ImageOptionsoptions=newImageOptions(ImageFormat.Png);intimageNumber=0;// Iterate over images
for(PageImageAreaimage:images){// Save the image to the png file
image.save(Constants.getOutputFilePath(String.format("%d.png",imageNumber)),options);imageNumber++;}}
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples: