Skip to main content
This article is about the legacy agentic-doc library. Use the landingai-ade library for all new projects.

Save Groundings as Images

When using any of the parsing functions from the library, you can use the optional grounding_save_dir parameter to save each grounding as an image. The images are saved to a directory you specify. Here’s an example of how to use the grounding_save_dir parameter with the parse parsing function:
from agentic_doc.parse import parse

# Parse a document from a URL & save groundings
results = parse(["https://www.rbcroyalbank.com/banking-services/_assets-custom/pdf/eStatement.pdf"],
                grounding_save_dir="./grounding")


# Print the path to each saved grounding
for chunk in results[0].chunks:
    for grounding in chunk.grounding:
        if grounding.image_path:
            print(f"Grounding saved to: {grounding.image_path}")

File Path and File Name Conventions for Saved Groundings

Images are saved with this structure:
path/to/save/groundings/
└── document_TIMESTAMP/
    └── page_0/
        └── ChunkType.TYPE_CHUNK_ID_Y.png
Where:
  • TIMESTAMP is the time and date the document was parsed
  • page_0 is the page number
  • TYPE is the chunk type
  • CHUNK_ID is the chunk ID
  • Y is the index of the grounding (in case a chunk spans multiple regions)
I