streamlit-pdf-viewer 0.0.19.dev2__tar.gz → 0.0.20.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/.bumpversion.toml +1 -1
  2. {streamlit_pdf_viewer-0.0.19.dev2/streamlit_pdf_viewer.egg-info → streamlit_pdf_viewer-0.0.20.dev0}/PKG-INFO +54 -11
  3. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/README.md +53 -10
  4. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/__init__.py +10 -2
  5. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/frontend/dist/index.html +1 -1
  6. streamlit_pdf_viewer-0.0.20.dev0/streamlit_pdf_viewer/frontend/dist/js/app.ebc5e2f4.js +2 -0
  7. streamlit_pdf_viewer-0.0.20.dev0/streamlit_pdf_viewer/frontend/dist/js/app.ebc5e2f4.js.map +1 -0
  8. streamlit_pdf_viewer-0.0.19.dev2/streamlit_pdf_viewer/frontend/dist/js/chunk-vendors.ffabda0e.js → streamlit_pdf_viewer-0.0.20.dev0/streamlit_pdf_viewer/frontend/dist/js/chunk-vendors.72a36d5a.js +8 -8
  9. streamlit_pdf_viewer-0.0.20.dev0/streamlit_pdf_viewer/frontend/dist/js/chunk-vendors.72a36d5a.js.map +1 -0
  10. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0/streamlit_pdf_viewer.egg-info}/PKG-INFO +54 -11
  11. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer.egg-info/SOURCES.txt +4 -4
  12. streamlit_pdf_viewer-0.0.19.dev2/streamlit_pdf_viewer/frontend/dist/js/app.ae269d4f.js +0 -2
  13. streamlit_pdf_viewer-0.0.19.dev2/streamlit_pdf_viewer/frontend/dist/js/app.ae269d4f.js.map +0 -1
  14. streamlit_pdf_viewer-0.0.19.dev2/streamlit_pdf_viewer/frontend/dist/js/chunk-vendors.ffabda0e.js.map +0 -1
  15. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/LICENSE +0 -0
  16. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/MANIFEST.in +0 -0
  17. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/setup.cfg +0 -0
  18. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/setup.py +0 -0
  19. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/frontend/dist/css/app.1df382f3.css +0 -0
  20. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/frontend/dist/css/chunk-vendors.8a2a8d65.css +0 -0
  21. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/frontend/dist/img/altText_add.7748ee93.svg +0 -0
  22. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/frontend/dist/img/altText_done.1026be11.svg +0 -0
  23. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/frontend/dist/img/cursor-editorFreeHighlight.1fed7bb7.svg +0 -0
  24. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/frontend/dist/img/cursor-editorFreeText.0b596377.svg +0 -0
  25. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/frontend/dist/img/cursor-editorInk.f94c2f42.svg +0 -0
  26. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/frontend/dist/img/cursor-editorTextHighlight.5636640c.svg +0 -0
  27. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/frontend/dist/img/editor-toolbar-delete.6694a89f.svg +0 -0
  28. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/frontend/dist/img/toolbarButton-editorHighlight.c3287eaa.svg +0 -0
  29. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer/frontend/dist/img/toolbarButton-menuArrow.37a6145d.svg +0 -0
  30. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer.egg-info/dependency_links.txt +0 -0
  31. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer.egg-info/requires.txt +0 -0
  32. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/streamlit_pdf_viewer.egg-info/top_level.txt +0 -0
  33. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/__init__.py +0 -0
  34. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/e2e_utils.py +0 -0
  35. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_embed_height.py +0 -0
  36. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_embed_no_args.py +0 -0
  37. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_embed_width.py +0 -0
  38. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_embed_width_height.py +0 -0
  39. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_iframe_height.py +0 -0
  40. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_iframe_no_args.py +0 -0
  41. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_iframe_width.py +0 -0
  42. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_iframe_width_height.py +0 -0
  43. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_invalid_params.py +0 -0
  44. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_rendering_text.py +0 -0
  45. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_resolution_boost.py +0 -0
  46. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_tabs.py +0 -0
  47. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_tabs_2.py +0 -0
  48. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_unwrap_height.py +0 -0
  49. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_unwrap_no_args.py +0 -0
  50. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_unwrap_width.py +0 -0
  51. {streamlit_pdf_viewer-0.0.19.dev2 → streamlit_pdf_viewer-0.0.20.dev0}/tests/test_unwrap_width_height.py +0 -0
@@ -1,5 +1,5 @@
1
1
  [tool.bumpversion]
2
- current_version = "0.0.19-dev2"
2
+ current_version = "0.0.20-dev0"
3
3
  commit = "true"
4
4
  tag = "true"
5
5
  tag_name = "v{new_version}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: streamlit-pdf-viewer
3
- Version: 0.0.19.dev2
3
+ Version: 0.0.20.dev0
4
4
  Summary: Streamlit component for PDF visualisation and manipulation
5
5
  Home-page: https://github.com/lfoppiano/streamlit-pdf-viewer
6
6
  Author: Luca Foppiano, Tomoya Mato
@@ -14,6 +14,7 @@ Requires-Dist: wheel; extra == "devel"
14
14
 
15
15
  [![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
16
16
  [![PyPI version](https://badge.fury.io/py/streamlit-pdf-viewer.svg)](https://badge.fury.io/py/streamlit-pdf-viewer)
17
+ [![Downloads](https://static.pepy.tech/badge/streamlit-pdf-viewer)](https://pepy.tech/project/streamlit-pdf-viewer)
17
18
  [![Build](https://github.com/lfoppiano/streamlit-pdf-viewer/actions/workflows/ci-build.yml/badge.svg)](https://github.com/lfoppiano/streamlit-pdf-viewer/actions/workflows/ci-build.yml)
18
19
  [![Coverage Status](https://coveralls.io/repos/github/lfoppiano/streamlit-pdf-viewer/badge.svg)](https://coveralls.io/github/lfoppiano/streamlit-pdf-viewer)
19
20
 
@@ -41,6 +42,17 @@ You can see an [application](https://github.com/lfoppiano/structure-vision) in a
41
42
  - The component is still in development, so expect some bugs and limitations
42
43
  - The streamlit reload at each action may render slowly for complex PDF documents
43
44
 
45
+ ## Caveats
46
+
47
+ Here some caveats to be aware of:
48
+ - It ss mandatory to specify a `width` to show PDF document on tabs and expanders, otherwise, the viewer will not be displayed on tabs not immediately visible.
49
+ - From version 0.0.16, the behavior for managing width and height has changed:
50
+ - If only the height is specified, the PDF document will be shown in proportion with the with proportional based on the PDF dimensions.
51
+ - The possibility to show a large view of half the PDF is not available anymore (let's face it, it was not very useful).
52
+ - If you need to use all the available space and limit the height, you can encapsulate the `pdf_viewer()` into a `st.component(width:...)` setting the width.
53
+ - The `legacy` rendering is not supported on Chrome, due to security reasons.
54
+
55
+
44
56
 
45
57
  ## Getting started
46
58
 
@@ -57,13 +69,6 @@ from streamlit_pdf_viewer import pdf_viewer
57
69
  pdf_viewer("str, path or bytes")
58
70
  ```
59
71
 
60
- ### Caveats
61
-
62
- Here some caveats to be aware of:
63
- - Is mandatory to specify a `width` to show PDF document on tabs and expanders, otherwise, the viewer will not be displayed on tabs not immediately visible.
64
- - The `legacy` rendering is not supported on Chrome, due to security reasons.
65
-
66
-
67
72
  ### Params
68
73
 
69
74
  In the following table the list of parameters that can be provided to the `pdf_viewer` function:
@@ -73,15 +78,15 @@ In the following table the list of parameters that can be provided to the `pdf_v
73
78
  | input | The source of the PDF file. Accepts a file path, URL, or binary data. |
74
79
  | width | Width of the PDF viewer in pixels. It defaults to 700 pixels. |
75
80
  | height | Height of the PDF viewer in pixels. If not provided, the viewer shows the whole content. |
76
- | annotations | A list of annotations to be overlaid on the PDF. Format is described here. |
81
+ | annotations | A list of annotations to be overlaid on the PDF. Format is described [here](#annotation-format). |
77
82
  | pages_vertical_spacing | The vertical space (in pixels) between each page of the PDF. Defaults to 2 pixels. |
78
83
  | annotation_outline_size | Size of the outline around each annotation in pixels. Defaults to 1 pixel. |
79
84
  | rendering | Type of rendering: `unwrap` (default), `legacy_iframe`, or `legacy_embed`. The default value, `unwrap` shows the PDF document using pdf.js, and supports the visualisation of annotations. Other values are `legacy_iframe` and `legacy_embed` which use the legacy approach of injecting the document into an `<embed>` or `<iframe>`. They allow viewing the PDF using the viewer of the browser that contains additional features we are still working to implement in this component. **IMPORTANT**: :warning: The "legacy" methods **work only with Firefox**, and **do not support annotations**. :warning: |
80
85
  | pages_to_render | Filter the rendering to a specific set of pages. By default, all pages are rendered. |
81
86
  | 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.
82
87
  | scroll_to_page | Scroll to a specific page when the component is rendered. Default is None. Require ints and ignores the parameters below zero. |
83
- | 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` |
84
-
88
+ | 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` |
89
+ | on_annotation_click | Callback function that is called when an annotation is clicked. The function receives the annotation as a parameter. |
85
90
 
86
91
  ### Annotation format
87
92
  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".
@@ -104,6 +109,44 @@ Here an example:
104
109
 
105
110
  The example shown in our screenshot can be found [here](resources/annotations.json).
106
111
 
112
+ ### How to use on_annotation_click
113
+
114
+ ```python
115
+ from streamlit_pdf_viewer import pdf_viewer
116
+
117
+ annotations = [
118
+ {
119
+ "page": 1,
120
+ "x": 220,
121
+ "y": 155,
122
+ "height": 22,
123
+ "width": 65,
124
+ "color": "red"
125
+ },
126
+ {
127
+ "page": 1,
128
+ "x": 220,
129
+ "y": 155,
130
+ "height": 22,
131
+ "width": 65,
132
+ "color": "red"
133
+ }
134
+ ]
135
+
136
+ def my_custom_annotation_handler(annotation):
137
+ print(f"Annotation {annotation} clicked.")
138
+
139
+ pdf_viewer(
140
+ "path/to/pdf",
141
+ on_annotation_click=my_custom_annotation_handler,
142
+ annotations=annotations
143
+ )
144
+
145
+ ```
146
+
147
+
148
+ ###
149
+
107
150
  ## Developers notes
108
151
 
109
152
  ### Environment
@@ -1,5 +1,6 @@
1
1
  [![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
2
2
  [![PyPI version](https://badge.fury.io/py/streamlit-pdf-viewer.svg)](https://badge.fury.io/py/streamlit-pdf-viewer)
3
+ [![Downloads](https://static.pepy.tech/badge/streamlit-pdf-viewer)](https://pepy.tech/project/streamlit-pdf-viewer)
3
4
  [![Build](https://github.com/lfoppiano/streamlit-pdf-viewer/actions/workflows/ci-build.yml/badge.svg)](https://github.com/lfoppiano/streamlit-pdf-viewer/actions/workflows/ci-build.yml)
4
5
  [![Coverage Status](https://coveralls.io/repos/github/lfoppiano/streamlit-pdf-viewer/badge.svg)](https://coveralls.io/github/lfoppiano/streamlit-pdf-viewer)
5
6
 
@@ -27,6 +28,17 @@ You can see an [application](https://github.com/lfoppiano/structure-vision) in a
27
28
  - The component is still in development, so expect some bugs and limitations
28
29
  - The streamlit reload at each action may render slowly for complex PDF documents
29
30
 
31
+ ## Caveats
32
+
33
+ Here some caveats to be aware of:
34
+ - It ss mandatory to specify a `width` to show PDF document on tabs and expanders, otherwise, the viewer will not be displayed on tabs not immediately visible.
35
+ - From version 0.0.16, the behavior for managing width and height has changed:
36
+ - If only the height is specified, the PDF document will be shown in proportion with the with proportional based on the PDF dimensions.
37
+ - The possibility to show a large view of half the PDF is not available anymore (let's face it, it was not very useful).
38
+ - If you need to use all the available space and limit the height, you can encapsulate the `pdf_viewer()` into a `st.component(width:...)` setting the width.
39
+ - The `legacy` rendering is not supported on Chrome, due to security reasons.
40
+
41
+
30
42
 
31
43
  ## Getting started
32
44
 
@@ -43,13 +55,6 @@ from streamlit_pdf_viewer import pdf_viewer
43
55
  pdf_viewer("str, path or bytes")
44
56
  ```
45
57
 
46
- ### Caveats
47
-
48
- Here some caveats to be aware of:
49
- - Is mandatory to specify a `width` to show PDF document on tabs and expanders, otherwise, the viewer will not be displayed on tabs not immediately visible.
50
- - The `legacy` rendering is not supported on Chrome, due to security reasons.
51
-
52
-
53
58
  ### Params
54
59
 
55
60
  In the following table the list of parameters that can be provided to the `pdf_viewer` function:
@@ -59,15 +64,15 @@ In the following table the list of parameters that can be provided to the `pdf_v
59
64
  | input | The source of the PDF file. Accepts a file path, URL, or binary data. |
60
65
  | width | Width of the PDF viewer in pixels. It defaults to 700 pixels. |
61
66
  | height | Height of the PDF viewer in pixels. If not provided, the viewer shows the whole content. |
62
- | annotations | A list of annotations to be overlaid on the PDF. Format is described here. |
67
+ | annotations | A list of annotations to be overlaid on the PDF. Format is described [here](#annotation-format). |
63
68
  | pages_vertical_spacing | The vertical space (in pixels) between each page of the PDF. Defaults to 2 pixels. |
64
69
  | annotation_outline_size | Size of the outline around each annotation in pixels. Defaults to 1 pixel. |
65
70
  | rendering | Type of rendering: `unwrap` (default), `legacy_iframe`, or `legacy_embed`. The default value, `unwrap` shows the PDF document using pdf.js, and supports the visualisation of annotations. Other values are `legacy_iframe` and `legacy_embed` which use the legacy approach of injecting the document into an `<embed>` or `<iframe>`. They allow viewing the PDF using the viewer of the browser that contains additional features we are still working to implement in this component. **IMPORTANT**: :warning: The "legacy" methods **work only with Firefox**, and **do not support annotations**. :warning: |
66
71
  | pages_to_render | Filter the rendering to a specific set of pages. By default, all pages are rendered. |
67
72
  | 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.
68
73
  | scroll_to_page | Scroll to a specific page when the component is rendered. Default is None. Require ints and ignores the parameters below zero. |
69
- | 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` |
70
-
74
+ | 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` |
75
+ | on_annotation_click | Callback function that is called when an annotation is clicked. The function receives the annotation as a parameter. |
71
76
 
72
77
  ### Annotation format
73
78
  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".
@@ -90,6 +95,44 @@ Here an example:
90
95
 
91
96
  The example shown in our screenshot can be found [here](resources/annotations.json).
92
97
 
98
+ ### How to use on_annotation_click
99
+
100
+ ```python
101
+ from streamlit_pdf_viewer import pdf_viewer
102
+
103
+ annotations = [
104
+ {
105
+ "page": 1,
106
+ "x": 220,
107
+ "y": 155,
108
+ "height": 22,
109
+ "width": 65,
110
+ "color": "red"
111
+ },
112
+ {
113
+ "page": 1,
114
+ "x": 220,
115
+ "y": 155,
116
+ "height": 22,
117
+ "width": 65,
118
+ "color": "red"
119
+ }
120
+ ]
121
+
122
+ def my_custom_annotation_handler(annotation):
123
+ print(f"Annotation {annotation} clicked.")
124
+
125
+ pdf_viewer(
126
+ "path/to/pdf",
127
+ on_annotation_click=my_custom_annotation_handler,
128
+ annotations=annotations
129
+ )
130
+
131
+ ```
132
+
133
+
134
+ ###
135
+
93
136
  ## Developers notes
94
137
 
95
138
  ### Environment
@@ -1,7 +1,7 @@
1
1
  import base64
2
2
  import os
3
3
  from pathlib import Path
4
- from typing import Union, List, Optional
4
+ from typing import Union, List, Optional, Callable
5
5
 
6
6
  import streamlit.components.v1 as components
7
7
  import json
@@ -39,7 +39,8 @@ def pdf_viewer(
39
39
  resolution_boost: int = 1,
40
40
  scroll_to_page: int = None,
41
41
  scroll_to_annotation: int = None,
42
- ):
42
+ on_annotation_click: Optional[Callable[[dict], None]] = None,
43
+ ):
43
44
  """
44
45
  pdf_viewer function to display a PDF file in a Streamlit app.
45
46
 
@@ -59,6 +60,7 @@ def pdf_viewer(
59
60
  :param resolution_boost: Boost the resolution by a factor from 2 to 10. Defaults to 1.
60
61
  :param scroll_to_page: Scroll to a specific page in the PDF. The parameter is an integer, which represent the positional value of the page. E.g. 1, will be the first page. Defaults to None.
61
62
  :param scroll_to_annotation: Scroll to a specific annotation in the PDF. The parameter is an integer, which represent the positional value of the annotation. E.g. 1, will be the first annotation. Defaults to None.
63
+ :param on_annotation_click: A callback function that will be called when an annotation is clicked. The function should accept a single argument, which is the annotation that was clicked. Defaults to None.
62
64
 
63
65
  The function reads the PDF file (from a file path, URL, or binary data), encodes it in base64,
64
66
  and uses a Streamlit component to render it in the app. It supports optional annotations and adjustable margins.
@@ -118,6 +120,12 @@ def pdf_viewer(
118
120
  scroll_to_page=scroll_to_page,
119
121
  scroll_to_annotation=scroll_to_annotation
120
122
  )
123
+
124
+ # Execute the custom callback function
125
+ if component_value and 'clicked_annotation' in component_value:
126
+ clicked_annotation = component_value['clicked_annotation']
127
+ if on_annotation_click is not None and callable(on_annotation_click):
128
+ on_annotation_click(clicked_annotation)
121
129
  return component_value
122
130
 
123
131
 
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>streamlit_pdf_viewer</title><script defer="defer" src="js/chunk-vendors.ffabda0e.js"></script><script defer="defer" src="js/app.ae269d4f.js"></script><link href="css/chunk-vendors.8a2a8d65.css" rel="stylesheet"><link href="css/app.1df382f3.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but streamlit_pdf_viewer doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>streamlit_pdf_viewer</title><script defer="defer" src="js/chunk-vendors.72a36d5a.js"></script><script defer="defer" src="js/app.ebc5e2f4.js"></script><link href="css/chunk-vendors.8a2a8d65.css" rel="stylesheet"><link href="css/app.1df382f3.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but streamlit_pdf_viewer doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
@@ -0,0 +1,2 @@
1
+ (()=>{"use strict";var e={5060:(e,t,n)=>{var a=n(3751),r=n(641);const i={id:"app"};function o(e,t,n,a,o,s){const l=(0,r.g2)("PdfViewer"),d=(0,r.g2)("WithStreamlitConnection");return(0,r.uX)(),(0,r.CE)("div",i,[(0,r.bF)(d,null,{default:(0,r.k6)((({args:e})=>[(0,r.bF)(l,{args:e},null,8,["args"])])),_:1})])}var s=n(33);const l={key:0},d={key:0,id:"pdfAnnotations"},c=["onClick"],p=["id"],g={key:1},u=["src","width","height"],h={key:2},v=["src","width","height"],w={key:3};function f(e,t,n,a,i,o){return(0,r.uX)(),(0,r.CE)("div",{id:"pdfContainer",style:(0,s.Tr)(a.pdfContainerStyle)},["unwrap"===n.args.rendering?((0,r.uX)(),(0,r.CE)("div",l,[(0,r.Lk)("div",{id:"pdfViewer",style:(0,s.Tr)(a.pdfViewerStyle)},[n.args.annotations?((0,r.uX)(),(0,r.CE)("div",d,[((0,r.uX)(!0),(0,r.CE)(r.FK,null,(0,r.pI)(a.filteredAnnotations,((e,t)=>((0,r.uX)(),(0,r.CE)("div",{key:t,style:(0,s.Tr)(a.getPageStyle),onClick:n=>a.handleAnnotationClick(e,t)},[(0,r.Lk)("div",{style:(0,s.Tr)(a.getAnnotationStyle(e,t)),id:`annotation-${t}`},null,12,p)],12,c)))),128))])):(0,r.Q3)("",!0)],4)])):"legacy_embed"===n.args.rendering?((0,r.uX)(),(0,r.CE)("div",g,[(0,r.Lk)("embed",{src:`data:application/pdf;base64,${n.args.binary}`,width:`${n.args.width}`,height:`${n.args.height}`,type:"application/pdf"},null,8,u)])):"legacy_iframe"===n.args.rendering?((0,r.uX)(),(0,r.CE)("div",h,[(0,r.Lk)("embed",{src:`data:application/pdf;base64,${n.args.binary}`,width:`${n.args.width}`,height:`${n.args.height}`,type:"application/pdf"},null,8,v)])):((0,r.uX)(),(0,r.CE)("div",w," Error rendering option. "))],4)}n(4114),n(7642),n(8004),n(3853),n(5876),n(2475),n(5024),n(1698),n(8992),n(4520);var m=n(953),y=(n(951),n(9936)),_=n(7445);const E="pdfjs-dist/cmaps/",C=!0,b=!0,k={props:["args"],setup(e){const t=(0,m.KR)(0),n=(0,m.KR)(0),a=(0,m.KR)([]),i=(0,m.KR)([]),o=(0,m.KR)([]),s=(0,m.KR)([]),l=0===e.args.pages_to_render.length,d=(0,r.EW)((()=>l?e.args.annotations:e.args.annotations.filter((t=>e.args.pages_to_render.includes(Number(t.page)))))),c=(e,t)=>{const n=JSON.parse(JSON.stringify(e));_.wk.setComponentValue({clicked_annotation:{index:t,...n}})},p=!0===e.args.render_text,g=(0,r.EW)((()=>({width:e.args.width?`${e.args.width}px`:`${n.value}px`,height:e.args.height?`${e.args.height}px`:"auto",overflow:"auto"}))),u={position:"relative"},h={position:"relative"},v=t=>{let n=0;if(l)for(let r=0;r<t-1;r++)n+=i.value[r]*a.value[r]+e.args.pages_vertical_spacing;else for(let r=0;r<i.value.length;r++)e.args.pages_to_render.includes(r+1)&&r<t-1&&(n+=i.value[r]*a.value[r]+e.args.pages_vertical_spacing);return n},w=(t,n)=>{const r=a.value[t.page-1],i={position:"absolute",left:t.x*r+"px",top:`${v(t.page)+t.y*r}px`,width:t.width*r+"px",height:t.height*r+"px",outline:e.args.annotation_outline_size*r+"px solid",outlineColor:t.color,cursor:"pointer","z-index":1};return n&&s.value.push(`annotation-${n}`),i},f=e=>{const t=e?.getElementsByTagName("canvas");for(let n=t.length-1;n>=0;n--)e?.removeChild(t.item(n))},k=(t,n,a,r,i=1)=>{const o=t.getViewport({scale:n,rotation:a}),s=(window.devicePixelRatio||1)*i,l=document.createElement("canvas");return l.id=`canvas_page_${r}`,l.height=o.height*s+e.args.pages_vertical_spacing,l.width=o.width*s,l.style.width=o.width+"px",l.style.height=o.height+"px",l.style.display="block",l.style.marginBottom=`${e.args.pages_vertical_spacing}px`,l.getContext("2d").scale(s,s),l},x=async(e,t,n)=>{const a={canvasContext:t.getContext("2d"),viewport:n};try{const t=e.render(a);await t.promise.catch((function(e){}))}catch(r){}if(p){const a=await e.getTextContent(),r=document.createElement("div");r.className="textLayer",r.style="z-index: 2";const i=new y.D6({textContentSource:a,container:r,viewport:n,textDivs:[]});await i.render(),requestAnimationFrame((async()=>{const e=document.createElement("div");e.className="page";const n=document.createElement("div");n.className="canvasWrapper",n.appendChild(t),e.style="position: relative;";const a=document.getElementById("pdfViewer");e.appendChild(n),e.appendChild(r),a.appendChild(e)}))}else requestAnimationFrame((()=>{const e=document.createElement("div");e.className="page";const n=document.createElement("div");n.className="canvasWrapper",n.appendChild(t),e.style="position: relative;",e.appendChild(n),pdfViewer.appendChild(e)}))},$=async(r,s,l=null)=>{if(0===l.length){l=[];for(let e=0;e<r.numPages;e++)l.push(e+1)}let d=1;e.args.resolution_boost&&(d=e.args.resolution_boost);for(let c=1;c<=r.numPages;c++){const p=await r.getPage(c),g=p.rotate,u=p.getViewport({scale:1,rotation:g});if(e.args.height>0){const t=u.width/u.height,a=t*e.args.height;(0===n.value||a<n.value)&&(n.value=a)}const h=n.value/u.width;if(a.value.push(h),i.value.push(u.height),l.includes(c)){const e=k(p,h,g,c,d);s.style.setProperty("--scale-factor",h);const n=p.getViewport({scale:a.value[p._pageIndex],rotation:p.rotate,intent:"print"}),r=(window.devicePixelRatio||1)*d;t.value+=e.height/r,await x(p,e,n),void 0!==e.id&&o.value.push(e.id)}}l.length>0&&(t.value-=e.args.pages_vertical_spacing)},S=e=>{window.alert(e.message),console.error(e)},V=async t=>{y.EA.workerSrc="pdfjs-dist/build/pdf.worker.mjs";try{const n=await(0,y.YE)({url:t,cMapUrl:E,cMapPacked:C,enableXfa:b}),a=document.getElementById("pdfViewer");f(a);const r=await n.promise;await $(r,a,e.args.pages_to_render)}catch(n){S(n)}},R=()=>{if(e.args.scroll_to_page){const t=document.getElementById(`canvas_page_${e.args.scroll_to_page}`);t&&t.scrollIntoView({behavior:"smooth"})}else if(e.args.scroll_to_annotation){const t=document.getElementById("annotation-"+(e.args.scroll_to_annotation-1));t&&t.scrollIntoView({behavior:"smooth",block:"center"})}},A=()=>{const e=new Set,t=new Set;let n;for(n=0;n<s.value.length;n++)t.add(s.value[n]);for(n=0;n<o.value.length;n++)e.add(o.value[n])},N=()=>{_.wk.setFrameHeight(e.args.height||t.value)},O=()=>{null===e.args.width||void 0===e.args.width?n.value=window.innerWidth:Number.isInteger(e.args.width)&&(n.value=e.args.width,window.innerWidth>0&&window.innerWidth<n.value&&(n.value=window.innerWidth))};return(0,r.sV)((()=>{const t=`data:application/pdf;base64,${e.args.binary}`;O(),"unwrap"===e.args.rendering?V(t).then(N).then(A):N()})),(0,r.$u)((()=>{N(),"unwrap"===e.args.rendering&&R()})),{filteredAnnotations:d,handleAnnotationClick:c,getAnnotationStyle:w,pdfContainerStyle:g,pdfViewerStyle:u,getPageStyle:h}}};var x=n(6262);const $=(0,x.A)(k,[["render",f]]),S=$,V={key:0},R={class:"err__msg"};function A(e,t,n,a,i,o){return(0,r.uX)(),(0,r.CE)("div",null,[""!=e.componentError?((0,r.uX)(),(0,r.CE)("div",V,[t[0]||(t[0]=(0,r.Lk)("h1",{class:"err__title"},"Component Error",-1)),(0,r.Lk)("div",R,"Message: "+(0,s.v_)(e.componentError),1)])):null!=e.renderData?(0,r.RG)(e.$slots,"default",{key:1,args:e.renderData.args,disabled:e.renderData.disabled},void 0,!0):(0,r.Q3)("",!0)])}const N=(0,r.pM)({name:"WithStreamlitConnection",setup(){const e=(0,m.KR)(void 0),t=(0,m.KR)(""),n=n=>{const a=n;e.value=a.detail,t.value=""};return(0,r.sV)((()=>{_.wk.events.addEventListener(_.wk.RENDER_EVENT,n),_.wk.setComponentReady()})),(0,r.$u)((()=>{""!=t.value&&_.wk.setFrameHeight()})),(0,r.hi)((()=>{_.wk.events.removeEventListener(_.wk.RENDER_EVENT,n)})),(0,r.qG)((e=>{t.value=String(e)})),{renderData:e,componentError:t}}}),O=(0,x.A)(N,[["render",A],["__scopeId","data-v-bef81972"]]),P=O,X=(0,r.pM)({name:"App",components:{PdfViewer:S,WithStreamlitConnection:P}}),W=(0,x.A)(X,[["render",o]]),I=W;(0,a.Ef)(I).mount("#app")}},t={};function n(a){var r=t[a];if(void 0!==r)return r.exports;var i=t[a]={exports:{}};return e[a].call(i.exports,i,i.exports,n),i.exports}n.m=e,(()=>{var e=[];n.O=(t,a,r,i)=>{if(!a){var o=1/0;for(c=0;c<e.length;c++){for(var[a,r,i]=e[c],s=!0,l=0;l<a.length;l++)(!1&i||o>=i)&&Object.keys(n.O).every((e=>n.O[e](a[l])))?a.splice(l--,1):(s=!1,i<o&&(o=i));if(s){e.splice(c--,1);var d=r();void 0!==d&&(t=d)}}return t}i=i||0;for(var c=e.length;c>0&&e[c-1][2]>i;c--)e[c]=e[c-1];e[c]=[a,r,i]}})(),(()=>{n.d=(e,t)=>{for(var a in t)n.o(t,a)&&!n.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})}})(),(()=>{n.g=function(){if("object"===typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"===typeof window)return window}}()})(),(()=>{n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{var e={524:0};n.O.j=t=>0===e[t];var t=(t,a)=>{var r,i,[o,s,l]=a,d=0;if(o.some((t=>0!==e[t]))){for(r in s)n.o(s,r)&&(n.m[r]=s[r]);if(l)var c=l(n)}for(t&&t(a);d<o.length;d++)i=o[d],n.o(e,i)&&e[i]&&e[i][0](),e[i]=0;return n.O(c)},a=self["webpackChunkstreamlit_pdf_viewer"]=self["webpackChunkstreamlit_pdf_viewer"]||[];a.forEach(t.bind(null,0)),a.push=t.bind(null,a.push.bind(a))})();var a=n.O(void 0,[504],(()=>n(5060)));a=n.O(a)})();
2
+ //# sourceMappingURL=app.ebc5e2f4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js/app.ebc5e2f4.js","mappings":"gEAEA,MAAMA,EAAa,CCIZC,GAAG,ODFJ,SAAUC,EAAOC,EAAUC,EAAYC,EAAYC,EAAYC,EAAWC,GAC9E,MAAMC,GAAuBC,EAAAA,EAAAA,IAAkB,aACzCC,GAAqCD,EAAAA,EAAAA,IAAkB,2BAE7D,OAAQE,EAAAA,EAAAA,OCFRC,EAAAA,EAAAA,IAIM,MAJNb,EAIM,EAHJc,EAAAA,EAAAA,IAE0BH,EAAA,MAT9BI,SAAAC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EAAW,CAAC,MAAM,IAAO8D,EAAoB,QAC7F+C,EAAsB/C,EAAoBS,EAAEsC,E","sources":["webpack://streamlit_pdf_viewer/./src/App.vue?9ab1","webpack://streamlit_pdf_viewer/./src/App.vue","webpack://streamlit_pdf_viewer/./src/PdfViewer.vue","webpack://streamlit_pdf_viewer/./src/PdfViewer.vue?f557","webpack://streamlit_pdf_viewer/./src/streamlit/WithStreamlitConnection.vue?8d46","webpack://streamlit_pdf_viewer/./src/streamlit/WithStreamlitConnection.vue","webpack://streamlit_pdf_viewer/./src/streamlit/WithStreamlitConnection.vue?1dfc","webpack://streamlit_pdf_viewer/./src/App.vue?7ccd","webpack://streamlit_pdf_viewer/./src/main.ts","webpack://streamlit_pdf_viewer/webpack/bootstrap","webpack://streamlit_pdf_viewer/webpack/runtime/chunk loaded","webpack://streamlit_pdf_viewer/webpack/runtime/define property getters","webpack://streamlit_pdf_viewer/webpack/runtime/global","webpack://streamlit_pdf_viewer/webpack/runtime/hasOwnProperty shorthand","webpack://streamlit_pdf_viewer/webpack/runtime/jsonp chunk loading","webpack://streamlit_pdf_viewer/webpack/startup"],"sourcesContent":["import { resolveComponent as _resolveComponent, createVNode as _createVNode, withCtx as _withCtx, openBlock as _openBlock, createElementBlock as _createElementBlock } from \"vue\"\n\nconst _hoisted_1 = { id: \"app\" }\n\nexport function render(_ctx: any,_cache: any,$props: any,$setup: any,$data: any,$options: any) {\n const _component_PdfViewer = _resolveComponent(\"PdfViewer\")!\n const _component_WithStreamlitConnection = _resolveComponent(\"WithStreamlitConnection\")!\n\n return (_openBlock(), _createElementBlock(\"div\", _hoisted_1, [\n _createVNode(_component_WithStreamlitConnection, null, {\n default: _withCtx(({ args }) => [\n _createVNode(_component_PdfViewer, { args: args }, null, 8, [\"args\"])\n ]),\n _: 1\n })\n ]))\n}","<!-- \n We bootstrap our Component to Streamlit with our scoped slot in the top-level App.\n This is where scoped slot passes Streamlit `args` data from itself to children MyComponent.\n You should not have to edit this, but are free to do so :)\n-->\n<template>\n <div id=\"app\">\n <WithStreamlitConnection v-slot=\"{ args }\">\n <PdfViewer :args=\"args\" />\n </WithStreamlitConnection>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport { defineComponent } from \"vue\"\nimport PdfViewer from \"./PdfViewer.vue\"\n\n// \"withStreamlitConnection\" is a scoped slot. It bootstraps the\n// connection between your component and the Streamlit app, and handles\n// passing arguments from Python -> Component.\n//\n// You don't need to edit withStreamlitConnection (but you're welcome to!).\nimport WithStreamlitConnection from \"./streamlit/WithStreamlitConnection.vue\"\n\nexport default defineComponent({\n name: \"App\",\n components: {\n PdfViewer,\n WithStreamlitConnection,\n },\n})\n</script>\n\n<style>\nbody {\n margin: 0;\n}\n#app {\n font-family: Avenir, Helvetica, Arial, sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n color: #2c3e50;\n}\n</style>\n","<template>\n <div id=\"pdfContainer\" :style=\"pdfContainerStyle\">\n <div v-if=\"args.rendering==='unwrap'\">\n <div id=\"pdfViewer\" :style=\"pdfViewerStyle\">\n <div id=\"pdfAnnotations\" v-if=\"args.annotations\">\n <div\n v-for=\"(annotation, index) in filteredAnnotations\"\n :key=\"index\"\n :style=\"getPageStyle\"\n @click=\"handleAnnotationClick(annotation, index)\"\n >\n <div\n :style=\"getAnnotationStyle(annotation, index)\"\n :id=\"`annotation-${index}`\"\n ></div>\n </div>\n </div>\n </div>\n </div>\n <div v-else-if=\"args.rendering==='legacy_embed'\">\n <embed :src=\"`data:application/pdf;base64,${args.binary}`\" :width=\"`${args.width}`\" :height=\"`${args.height}`\" type=\"application/pdf\"/>\n </div>\n <div v-else-if=\"args.rendering==='legacy_iframe'\">\n <embed :src=\"`data:application/pdf;base64,${args.binary}`\" :width=\"`${args.width}`\" :height=\"`${args.height}`\" type=\"application/pdf\"/>\n </div>\n <div v-else>\n Error rendering option.\n </div>\n </div>\n</template>\n\n<script>\nimport { onMounted, onUpdated, computed, ref} from \"vue\";\nimport \"pdfjs-dist/web/pdf_viewer.css\";\nimport \"pdfjs-dist/build/pdf.worker.mjs\";\nimport {getDocument} from \"pdfjs-dist/build/pdf\";\nimport {Streamlit} from \"streamlit-component-lib\";\nimport * as pdfjsLib from \"pdfjs-dist\";\n\nconst CMAP_URL = \"pdfjs-dist/cmaps/\";\nconst CMAP_PACKED = true;\nconst ENABLE_XFA = true;\n\nexport default {\n props: [\"args\"],\n\n setup(props) {\n const totalHeight = ref(0);\n const maxWidth = ref(0);\n const pageScales = ref([]);\n const pageHeights = ref([]);\n const loadedPages = ref([]);\n const loadedAnnotations = ref([]);\n\n const isRenderingAllPages = props.args.pages_to_render.length === 0;\n\n const filteredAnnotations = computed(() => {\n if (isRenderingAllPages) {\n return props.args.annotations;\n }\n return props.args.annotations.filter(anno => {\n return props.args.pages_to_render.includes(Number(anno.page))\n })\n });\n\n const handleAnnotationClick = (annotation, index) => {\n // Convert the Proxy object to a plain object\n const serializedAnnotation = JSON.parse(JSON.stringify(annotation));\n\n // Send data to Streamlit\n Streamlit.setComponentValue({\n clicked_annotation: { index, ...serializedAnnotation },\n });\n };\n\n const renderText = props.args.render_text === true\n\n const pdfContainerStyle = computed(() => ({\n width: props.args.width ? `${props.args.width}px` : `${maxWidth.value}px`,\n height: props.args.height ? `${props.args.height}px` : 'auto',\n overflow: 'auto',\n }));\n\n const pdfViewerStyle = {position: 'relative'};\n const getPageStyle = {position: 'relative'};\n\n const calculatePdfsHeight = (page) => {\n let height = 0;\n if (isRenderingAllPages) {\n for (let i = 0; i < page - 1; i++) {\n height += pageHeights.value[i] * pageScales.value[i] + props.args.pages_vertical_spacing; // Add margin for each page\n }\n } else {\n for (let i = 0; i < pageHeights.value.length; i++) {\n if (props.args.pages_to_render.includes(i + 1) && i < page - 1) {\n height += pageHeights.value[i] * pageScales.value[i] + props.args.pages_vertical_spacing;\n }\n }\n }\n return height;\n };\n\n const getAnnotationStyle = (annoObj, index) => {\n const scale = pageScales.value[annoObj.page - 1];\n const obj = {\n position: 'absolute',\n left: `${annoObj.x * scale}px`,\n top: `${calculatePdfsHeight(annoObj.page) + annoObj.y * scale}px`,\n width: `${annoObj.width * scale}px`,\n height: `${annoObj.height * scale}px`,\n outline: `${props.args.annotation_outline_size * scale}px solid`,\n outlineColor: annoObj.color,\n cursor: 'pointer',\n 'z-index': 1\n };\n if (index) {\n loadedAnnotations.value.push(`annotation-${index}`);\n }\n return obj\n };\n\n const clearExistingCanvases = (pdfViewer) => {\n const canvases = pdfViewer?.getElementsByTagName(\"canvas\");\n for (let j = canvases.length - 1; j >= 0; j--) {\n pdfViewer?.removeChild(canvases.item(j));\n }\n };\n\n const createCanvasForPage = (page, scale, rotation, pageNumber, resolutionRatioBoost=1) => {\n const viewport = page.getViewport({scale, rotation});\n\n const ratio = (window.devicePixelRatio || 1) * resolutionRatioBoost\n // console.log(ratio)\n\n const canvas = document.createElement(\"canvas\");\n canvas.id = `canvas_page_${pageNumber}`;\n canvas.height = viewport.height * ratio + props.args.pages_vertical_spacing;\n canvas.width = viewport.width * ratio;\n canvas.style.width = viewport.width + 'px';\n canvas.style.height = viewport.height + 'px';\n canvas.style.display = \"block\";\n canvas.style.marginBottom = `${props.args.pages_vertical_spacing}px`;\n canvas.getContext(\"2d\").scale(ratio, ratio);\n return canvas;\n };\n\n\n const renderPage = async (page, canvas, viewport) => {\n const renderContext = {\n canvasContext: canvas.getContext(\"2d\"),\n viewport: viewport\n };\n\n try {\n const renderTask = page.render(renderContext);\n await renderTask.promise.catch(function(error){\n // alertError(error);\n // do nothing\n });\n } catch (e) {\n // do nothing\n }\n\n\n if (renderText) {\n const textContent = await page.getTextContent();\n const textLayerDiv = document.createElement(\"div\");\n textLayerDiv.className = \"textLayer\"\n textLayerDiv.style = \"z-index: 2\"\n // textLayerDiv.style.position = \"absolute\";\n // textLayerDiv.style.height = `${viewport.height}px`;\n // textLayerDiv.style.width = `${viewport.width}px`;\n const textLayer = new pdfjsLib.TextLayer({\n textContentSource: textContent,\n container: textLayerDiv,\n viewport: viewport,\n textDivs: []\n })\n await textLayer.render()\n\n requestAnimationFrame(async () => {\n const pageDiv = document.createElement('div');\n pageDiv.className = 'page';\n\n const canvasWrapper = document.createElement('div');\n canvasWrapper.className = 'canvasWrapper';\n canvasWrapper.appendChild(canvas);\n\n pageDiv.style = \"position: relative;\";\n\n const pdfViewer = document.getElementById(\"pdfViewer\");\n pageDiv.appendChild(canvasWrapper);\n pageDiv.appendChild(textLayerDiv);\n\n pdfViewer.appendChild(pageDiv);\n });\n } else {\n requestAnimationFrame(() => {\n const pageDiv = document.createElement('div');\n pageDiv.className = 'page';\n\n const canvasWrapper = document.createElement('div');\n canvasWrapper.className = 'canvasWrapper';\n canvasWrapper.appendChild(canvas);\n\n pageDiv.style = \"position: relative;\";\n pageDiv.appendChild(canvasWrapper);\n pdfViewer.appendChild(pageDiv);\n });\n }\n };\n\n const renderPdfPages = async (pdf, pdfViewer, pagesToRender = null) => {\n if (pagesToRender.length === 0) {\n pagesToRender = []\n for (let i = 0; i < pdf.numPages; i++) {\n pagesToRender.push(i + 1);\n }\n }\n\n let resolutionBoost = 1\n if (props.args.resolution_boost) {\n resolutionBoost = props.args.resolution_boost\n }\n\n for (let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++) {\n const page = await pdf.getPage(pageNumber)\n const rotation = page.rotate\n // Initial viewport\n const unscaledViewport = page.getViewport({\n scale: 1.0,\n rotation: rotation,\n })\n\n if (props.args.height > 0) {\n const widthScale = unscaledViewport.width / unscaledViewport.height\n const possibleScaledWidth = widthScale * props.args.height\n if (maxWidth.value === 0) {\n maxWidth.value = possibleScaledWidth\n } else if (possibleScaledWidth < maxWidth.value) {\n maxWidth.value = possibleScaledWidth\n }\n }\n\n const scale = maxWidth.value / unscaledViewport.width\n\n pageScales.value.push(scale)\n pageHeights.value.push(unscaledViewport.height)\n if (pagesToRender.includes(pageNumber)) {\n const canvas = createCanvasForPage(page, scale, rotation, pageNumber, resolutionBoost)\n\n // pdfViewer?.append(canvas)\n pdfViewer.style.setProperty('--scale-factor', scale);\n\n const viewport = page.getViewport({\n scale: pageScales.value[page._pageIndex],\n rotation: page.rotate,\n intent: \"print\",\n });\n\n const ratio = (window.devicePixelRatio || 1) * resolutionBoost\n totalHeight.value += canvas.height / ratio\n await renderPage(page, canvas, viewport)\n if (canvas.id !== undefined) {\n loadedPages.value.push(canvas.id)\n }\n }\n }\n // Subtract the margin for the last page as it's not needed\n if (pagesToRender.length > 0) {\n totalHeight.value -= props.args.pages_vertical_spacing;\n }\n };\n\n const alertError = (error) => {\n window.alert(error.message);\n console.error(error);\n };\n\n const loadPdfs = async (url) => {\n pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdfjs-dist/build/pdf.worker.mjs';\n try {\n const loadingTask = await getDocument({\n url: url,\n cMapUrl: CMAP_URL,\n cMapPacked: CMAP_PACKED,\n enableXfa: ENABLE_XFA,\n });\n const pdfViewer = document.getElementById(\"pdfViewer\");\n clearExistingCanvases(pdfViewer);\n\n const pdf = await loadingTask.promise;\n await renderPdfPages(pdf, pdfViewer, props.args.pages_to_render);\n } catch (error) {\n alertError(error);\n }\n };\n\n const scrollToItem = () => {\n if (props.args.scroll_to_page) {\n const page = document.getElementById(`canvas_page_${props.args.scroll_to_page}`);\n if (page) {\n page.scrollIntoView({behavior: \"smooth\"});\n }\n } else if (props.args.scroll_to_annotation) {\n const annotation = document.getElementById(`annotation-${props.args.scroll_to_annotation - 1}`);\n if (annotation) {\n annotation.scrollIntoView({behavior: \"smooth\", block: \"center\"});\n }\n }\n };\n\n const collectAndReturnIds = () => {\n const pages_ids = new Set()\n const annotations_ids = new Set()\n\n let j\n\n for (j = 0; j < loadedAnnotations.value.length; j++) {\n annotations_ids.add(loadedAnnotations.value[j]);\n }\n for (j = 0; j < loadedPages.value.length; j++) {\n pages_ids.add(loadedPages.value[j]);\n }\n\n // Streamlit.setComponentValue({\"pages\": Array.from(pages_ids), \"annotations\": Array.from(annotations_ids)})\n }\n\n\n const setFrameHeight = () => {\n Streamlit.setFrameHeight(props.args.height || totalHeight.value);\n };\n\n const setFrameWidth = () => {\n if (props.args.width === null || props.args.width === undefined) {\n maxWidth.value = window.innerWidth\n } else if (Number.isInteger(props.args.width)) {\n maxWidth.value = props.args.width\n\n // If the desired width is larger than the available inner width,\n // we should not exceed it. To be revised\n if (window.innerWidth > 0) {\n if (window.innerWidth < maxWidth.value) {\n maxWidth.value = window.innerWidth\n }\n }\n }\n }\n\n onMounted(() => {\n const binaryDataUrl = `data:application/pdf;base64,${props.args.binary}`;\n setFrameWidth();\n if (props.args.rendering === \"unwrap\") {\n loadPdfs(binaryDataUrl)\n .then(setFrameHeight)\n .then(collectAndReturnIds)\n // .then(scrollToItem)\n //LF calling setComponentReady seems to be done anyway by the WithStreamlitConnection.vue\n // .then(Streamlit.setComponentReady);\n } else {\n setFrameHeight();\n // Streamlit.setComponentReady();\n }\n });\n\n onUpdated(() => {\n setFrameHeight();\n if (props.args.rendering === \"unwrap\") {\n scrollToItem();\n }\n });\n\n\n return {\n filteredAnnotations,\n handleAnnotationClick,\n getAnnotationStyle,\n pdfContainerStyle,\n pdfViewerStyle,\n getPageStyle\n };\n },\n};\n</script>\n","import { render } from \"./PdfViewer.vue?vue&type=template&id=3c58901a\"\nimport script from \"./PdfViewer.vue?vue&type=script&lang=js\"\nexport * from \"./PdfViewer.vue?vue&type=script&lang=js\"\n\nimport exportComponent from \"../node_modules/vue-loader/dist/exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render]])\n\nexport default __exports__","import { createElementVNode as _createElementVNode, toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode, renderSlot as _renderSlot } from \"vue\"\n\nconst _hoisted_1 = { key: 0 }\nconst _hoisted_2 = { class: \"err__msg\" }\n\nexport function render(_ctx: any,_cache: any,$props: any,$setup: any,$data: any,$options: any) {\n return (_openBlock(), _createElementBlock(\"div\", null, [\n (_ctx.componentError != '')\n ? (_openBlock(), _createElementBlock(\"div\", _hoisted_1, [\n _cache[0] || (_cache[0] = _createElementVNode(\"h1\", { class: \"err__title\" }, \"Component Error\", -1)),\n _createElementVNode(\"div\", _hoisted_2, \"Message: \" + _toDisplayString(_ctx.componentError), 1)\n ]))\n : (_ctx.renderData != null)\n ? _renderSlot(_ctx.$slots, \"default\", {\n key: 1,\n args: _ctx.renderData.args,\n disabled: _ctx.renderData.disabled\n }, undefined, true)\n : _createCommentVNode(\"\", true)\n ]))\n}","<template>\n <div>\n <!-- Error boundary. If our wrapped component threw an error, display it. -->\n <div v-if=\"componentError != ''\">\n <h1 class=\"err__title\">Component Error</h1>\n <div class=\"err__msg\">Message: {{ componentError }}</div>\n </div>\n <!-- \n Else render the component slot and pass Streamlit event data in `args` props to it.\n Don't render until we've gotten our first RENDER_EVENT from Streamlit.\n All components get disabled while the app is being re-run, and become re-enabled when the re-run has finished.\n -->\n <slot\n v-else-if=\"renderData != null\"\n :args=\"renderData.args\"\n :disabled=\"renderData.disabled\"\n ></slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport {\n ref,\n defineComponent,\n onMounted,\n onUpdated,\n onUnmounted,\n onErrorCaptured,\n} from \"vue\"\nimport { Streamlit, RenderData } from \"streamlit-component-lib\"\n\nexport default defineComponent({\n name: \"WithStreamlitConnection\",\n setup() {\n const renderData = ref<RenderData>((undefined as unknown) as RenderData)\n const componentError = ref(\"\")\n\n const onRenderEvent = (event: Event): void => {\n const renderEvent = event as CustomEvent<RenderData>\n renderData.value = renderEvent.detail\n componentError.value = \"\"\n }\n\n // Set up event listeners, and signal to Streamlit that we're ready.\n // We won't render the component until we receive the first RENDER_EVENT.\n onMounted(() => {\n Streamlit.events.addEventListener(Streamlit.RENDER_EVENT, onRenderEvent)\n Streamlit.setComponentReady()\n })\n onUpdated(() => {\n // If our slot threw an error, we display it in render(). In this\n // case, the slot won't be mounted and therefore won't call\n // `setFrameHeight` on its own. We do it here so that the rendered\n // error will be visible.\n if (componentError.value != \"\") {\n Streamlit.setFrameHeight()\n }\n })\n onUnmounted(() => {\n Streamlit.events.removeEventListener(\n Streamlit.RENDER_EVENT,\n onRenderEvent\n )\n })\n onErrorCaptured(err => {\n componentError.value = String(err)\n })\n\n return {\n renderData,\n componentError,\n }\n },\n})\n</script>\n\n<style scoped>\n.err__title,\n.err__msg {\n margin: 0;\n}\n</style>\n","import { render } from \"./WithStreamlitConnection.vue?vue&type=template&id=bef81972&scoped=true&ts=true\"\nimport script from \"./WithStreamlitConnection.vue?vue&type=script&lang=ts\"\nexport * from \"./WithStreamlitConnection.vue?vue&type=script&lang=ts\"\n\nimport \"./WithStreamlitConnection.vue?vue&type=style&index=0&id=bef81972&scoped=true&lang=css\"\n\nimport exportComponent from \"../../node_modules/vue-loader/dist/exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render],['__scopeId',\"data-v-bef81972\"]])\n\nexport default __exports__","import { render } from \"./App.vue?vue&type=template&id=6ea7f320&ts=true\"\nimport script from \"./App.vue?vue&type=script&lang=ts\"\nexport * from \"./App.vue?vue&type=script&lang=ts\"\n\nimport \"./App.vue?vue&type=style&index=0&id=6ea7f320&lang=css\"\n\nimport exportComponent from \"../node_modules/vue-loader/dist/exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render]])\n\nexport default __exports__","import { createApp } from 'vue'\nimport App from './App.vue'\n\ncreateApp(App).mount('#app')\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n// expose the modules object (__webpack_modules__)\n__webpack_require__.m = __webpack_modules__;\n\n","var deferred = [];\n__webpack_require__.O = (result, chunkIds, fn, priority) => {\n\tif(chunkIds) {\n\t\tpriority = priority || 0;\n\t\tfor(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];\n\t\tdeferred[i] = [chunkIds, fn, priority];\n\t\treturn;\n\t}\n\tvar notFulfilled = Infinity;\n\tfor (var i = 0; i < deferred.length; i++) {\n\t\tvar [chunkIds, fn, priority] = deferred[i];\n\t\tvar fulfilled = true;\n\t\tfor (var j = 0; j < chunkIds.length; j++) {\n\t\t\tif ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {\n\t\t\t\tchunkIds.splice(j--, 1);\n\t\t\t} else {\n\t\t\t\tfulfilled = false;\n\t\t\t\tif(priority < notFulfilled) notFulfilled = priority;\n\t\t\t}\n\t\t}\n\t\tif(fulfilled) {\n\t\t\tdeferred.splice(i--, 1)\n\t\t\tvar r = fn();\n\t\t\tif (r !== undefined) result = r;\n\t\t}\n\t}\n\treturn result;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.g = (function() {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// no baseURI\n\n// object to store loaded and loading chunks\n// undefined = chunk not loaded, null = chunk preloaded/prefetched\n// [resolve, reject, Promise] = chunk loading, 0 = chunk loaded\nvar installedChunks = {\n\t524: 0\n};\n\n// no chunk on demand loading\n\n// no prefetching\n\n// no preloaded\n\n// no HMR\n\n// no HMR manifest\n\n__webpack_require__.O.j = (chunkId) => (installedChunks[chunkId] === 0);\n\n// install a JSONP callback for chunk loading\nvar webpackJsonpCallback = (parentChunkLoadingFunction, data) => {\n\tvar [chunkIds, moreModules, runtime] = data;\n\t// add \"moreModules\" to the modules object,\n\t// then flag all \"chunkIds\" as loaded and fire callback\n\tvar moduleId, chunkId, i = 0;\n\tif(chunkIds.some((id) => (installedChunks[id] !== 0))) {\n\t\tfor(moduleId in moreModules) {\n\t\t\tif(__webpack_require__.o(moreModules, moduleId)) {\n\t\t\t\t__webpack_require__.m[moduleId] = moreModules[moduleId];\n\t\t\t}\n\t\t}\n\t\tif(runtime) var result = runtime(__webpack_require__);\n\t}\n\tif(parentChunkLoadingFunction) parentChunkLoadingFunction(data);\n\tfor(;i < chunkIds.length; i++) {\n\t\tchunkId = chunkIds[i];\n\t\tif(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {\n\t\t\tinstalledChunks[chunkId][0]();\n\t\t}\n\t\tinstalledChunks[chunkId] = 0;\n\t}\n\treturn __webpack_require__.O(result);\n}\n\nvar chunkLoadingGlobal = self[\"webpackChunkstreamlit_pdf_viewer\"] = self[\"webpackChunkstreamlit_pdf_viewer\"] || [];\nchunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));\nchunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));","// startup\n// Load entry module and return exports\n// This entry module depends on other loaded chunks and execution need to be delayed\nvar __webpack_exports__ = __webpack_require__.O(undefined, [504], () => (__webpack_require__(5060)))\n__webpack_exports__ = __webpack_require__.O(__webpack_exports__);\n"],"names":["_hoisted_1","id","render","_ctx","_cache","$props","$setup","$data","$options","_component_PdfViewer","_resolveComponent","_component_WithStreamlitConnection","_openBlock","_createElementBlock","_createVNode","default","_withCtx","args","_","key","style","_normalizeStyle","pdfContainerStyle","rendering","_createElementVNode","pdfViewerStyle","annotations","_hoisted_2","_Fragment","_renderList","filteredAnnotations","annotation","index","getPageStyle","onClick","$event","handleAnnotationClick","getAnnotationStyle","_hoisted_4","_hoisted_3","_createCommentVNode","_hoisted_5","src","binary","width","height","type","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","CMAP_URL","CMAP_PACKED","ENABLE_XFA","props","setup","totalHeight","ref","maxWidth","pageScales","pageHeights","loadedPages","loadedAnnotations","isRenderingAllPages","pages_to_render","length","computed","filter","anno","includes","Number","page","serializedAnnotation","JSON","parse","stringify","Streamlit","setComponentValue","clicked_annotation","renderText","render_text","value","overflow","position","calculatePdfsHeight","i","pages_vertical_spacing","annoObj","scale","obj","left","x","top","y","outline","annotation_outline_size","outlineColor","color","cursor","push","clearExistingCanvases","pdfViewer","canvases","getElementsByTagName","j","removeChild","item","createCanvasForPage","rotation","pageNumber","resolutionRatioBoost","viewport","getViewport","ratio","window","devicePixelRatio","canvas","document","createElement","display","marginBottom","getContext","renderPage","async","renderContext","canvasContext","renderTask","promise","catch","error","e","textContent","getTextContent","textLayerDiv","className","textLayer","pdfjsLib","textContentSource","container","textDivs","requestAnimationFrame","pageDiv","canvasWrapper","appendChild","getElementById","renderPdfPages","pdf","pagesToRender","numPages","resolutionBoost","resolution_boost","getPage","rotate","unscaledViewport","widthScale","possibleScaledWidth","setProperty","_pageIndex","intent","undefined","alertError","alert","message","console","loadPdfs","workerSrc","loadingTask","getDocument","url","cMapUrl","cMapPacked","enableXfa","scrollToItem","scroll_to_page","scrollIntoView","behavior","scroll_to_annotation","block","collectAndReturnIds","pages_ids","Set","annotations_ids","add","setFrameHeight","setFrameWidth","innerWidth","isInteger","onMounted","binaryDataUrl","then","onUpdated","__exports__","class","componentError","_toDisplayString","renderData","_renderSlot","$slots","disabled","defineComponent","name","onRenderEvent","event","renderEvent","detail","events","addEventListener","RENDER_EVENT","setComponentReady","onUnmounted","removeEventListener","onErrorCaptured","err","String","components","PdfViewer","WithStreamlitConnection","createApp","App","mount","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","exports","module","__webpack_modules__","call","m","deferred","O","result","chunkIds","fn","priority","notFulfilled","Infinity","fulfilled","Object","keys","every","splice","r","d","definition","o","defineProperty","enumerable","get","g","globalThis","this","Function","prop","prototype","hasOwnProperty","installedChunks","chunkId","webpackJsonpCallback","parentChunkLoadingFunction","data","moreModules","runtime","some","chunkLoadingGlobal","self","forEach","bind","__webpack_exports__"],"sourceRoot":""}