Extract images to files

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Parser MCP server lets your agent work with files on your machine; they are never uploaded. It runs in Docker: replace /path/to/documents with the folder it may use.

claude mcp add groupdocs-parser -- docker run --rm -i -v /path/to/documents:/data ghcr.io/groupdocs-parser/parser-net-mcp:latest
Folders, licensing and more →

Here are the steps to extract images to files:

  • Instantiate Parser object for the initial document;
  • Call getImages method and obtain collection of PageImageArea objects;
  • 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 (Parser parser = new Parser(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
    ImageOptions options = new ImageOptions(ImageFormat.Png);

    int imageNumber = 0;
    // Iterate over images
    for (PageImageArea image : 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:

Free online image extractor App

Along with full featured Java library we provide simple, but powerful free Apps.

You are welcome to extract images from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online GroupDocs Parser App.