Skip to content

Commit

Permalink
added documentation for on_annotation_click on README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
t29mato committed Dec 12, 2024
1 parent ccde4c1 commit 6a44f5e
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ In the following table the list of parameters that can be provided to the `pdf_v
| pages_to_render | Filter the rendering to a specific set of pages. By default, all pages are rendered. |
| render_text | Enable a layer of text on top of the PDF document. The text may be selected and copied. **NOTE** to avoid breaking existing deployments, we made this optional at first, also considering that having many annotations might interfere with the copy-paste.
| scroll_to_page | Scroll to a specific page when the component is rendered. Default is None. Require ints and ignores the parameters below zero. |
| scroll_to_annotation | Scroll to a specific annotation when the component is rendered. Default is None. Mutually exclusive with `scroll_to_page`. Raise an exception if used with `scroll_to_page` |

| scroll_to_annotation | Scroll to a specific annotation when the component is rendered. Default is None. Mutually exclusive with `scroll_to_page`. Raise an exception if used with `scroll_to_page` |
| on_annotation_click | Callback function that is called when an annotation is clicked. The function receives the annotation as a parameter. |

### Annotation format
The annotations format has been derived from the [Grobid's coordinate formats](https://grobid.readthedocs.io/en/latest/Coordinates-in-PDF/), which are described as a list of "bounding boxes".
Expand All @@ -91,6 +91,44 @@ Here an example:

The example shown in our screenshot can be found [here](resources/annotations.json).

### How to use on_annotation_click

```python
from streamlit_pdf_viewer import pdf_viewer

annotations = [
{
"page": 1,
"x": 220,
"y": 155,
"height": 22,
"width": 65,
"color": "red"
},
{
"page": 1,
"x": 220,
"y": 155,
"height": 22,
"width": 65,
"color": "red"
}
]

def my_custom_annotation_handler(annotation):
print(f"Annotation {annotation} clicked.")

pdf_viewer(
"path/to/pdf",
on_annotation_click=my_custom_annotation_handler,
annotations=annotations
)

```


###

## Developers notes

### Environment
Expand Down

0 comments on commit 6a44f5e

Please sign in to comment.