Check if collection isn’t null (images extraction is supported for the document);
Iterate through the collection and get sizes, image types and image contents.
The following example shows how to extract only images from the upper-left corner:
// Create an instance of Parser class
try(Parserparser=newParser(Constants.SampleImagesPdf)){// Create the options which are used for images extraction
PageAreaOptionsoptions=newPageAreaOptions(newRectangle(newPoint(340,150),newSize(300,100)));// Extract images from the upper-left corner of a page:
Iterable<PageImageArea>images=parser.getImages(options);// Check if images extraction is supported
if(images==null){System.out.println("Page images extraction isn't supported");return;}// Iterate over images
for(PageImageAreaimage:images){// Print a page index, rectangle and image type:
System.out.println(String.format("Page: %d, R: %s, Type: %s",image.getPage().getIndex(),image.getRectangle(),image.getFileType()));}}
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples: