Skip to main content
Use this script to see how the Parse API divided a document into blocks. It draws a box around every block on each page, colored by block type and labeled with the block’s ID (such as text-0 or table-0). Inside each table, every cell gets a thin box with no label, so the labels don’t cover the table text. The script reads the structure tree of the parse response. Every page node lists the blocks on that page as children, a table block lists its cells, and each node carries a grounding object with its page number and box. See Structure: Pages and Blocks. Two details matter when you draw on the page:
  • Page numbers are 1-indexed. grounding.page is 1 for the first page, while PDF libraries such as PyMuPDF number pages from 0. The script subtracts 1 when it opens a page.
  • Boxes are fractions of the page. xmin and xmax are fractions of the page width, and ymin and ymax are fractions of the page height, from 0 to 1. Multiply them by the width and height of the rendered page image. See Working with Boxes.
For PDFs, the script saves one annotated PNG per page (page_1_annotated.png, page_2_annotated.png). For image files, it saves page_annotated.png. The Python script draws on PDFs and every image type Parse accepts. The TypeScript script draws on PDF, PNG, and JPEG files. For any other file, such as a DOCX file or a spreadsheet, the script prints a message and saves nothing:
  • Text documents and presentations: Parse converts them to PDF before parsing, so there is no page image to match the boxes to. To see the boxes, convert the document to PDF and parse the PDF.
  • Spreadsheets: sheets have no page boxes. Their cells are grounded by address.
The script also skips any page 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