Skip to main content
Use this script to crop each block the Parse API found and save it as a separate PNG. Use the crops to build datasets, review parsing quality block by block, or process individual regions of a document. The script reads the structure tree of the parse response: each page node lists the blocks on that page as children, and each block carries a grounding object with its 1-indexed page number and a box in fractions of the page width and height. See Structure: Pages and Blocks. Each table is saved as one image. The Python script crops PDFs and every image type Parse accepts. The TypeScript script crops PDF, PNG, and JPEG files. For any other file, the script prints a message and saves nothing. Parse converts text documents and presentations to PDF before parsing, so to crop blocks from a DOCX or PPTX file, convert it to PDF and parse the PDF. Spreadsheets have no page boxes. The script also skips pages that failed to parse, and saves nothing when no page is left (an image whose only page failed).
These examples require the Python or TypeScript client library. Before running a script, set your API key and install the library and any required dependencies.

Scripts

Directory Structure for Saved Images

The scripts save the images in this structure:
Where:
  • TIMESTAMP is the date and time the script ran (format: YYYYMMDD_HHMMSS for Python, ISO format for TypeScript).
  • page_1 is the 1-indexed page number, the same value as the block’s grounding.page.
  • BLOCK_ID is the block’s id, in the format <type>-<index>. The index counts blocks of each type in reading order across the whole document, so text-2 is the document’s third text block, wherever it appears. See Common Block Fields.
For example, a two-page document with a table and a figure on the first page could produce: