Skip to content

Commit 292c359

Browse files
authored
Remove legacy methods for rendering the PDF documents (#96)
* remove legacy methods that are not working consistently, and related tests * update github actions
1 parent bd225cb commit 292c359

29 files changed

Lines changed: 172 additions & 674 deletions

.github/workflows/ci-build.yml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ concurrency:
99

1010
jobs:
1111
build:
12-
runs-on: ubuntu-latest
1312
strategy:
1413
matrix:
15-
python-version: [ 3.8, 3.9, '3.10', '3.11', '3.12', '3.13']
14+
os: [ubuntu-latest]
15+
python-version: [ '3.10', '3.11', '3.12', '3.13']
1616
node-version: [ 18, 20 ]
17+
18+
runs-on: ${{ matrix.os }}
19+
1720
steps:
1821
- uses: actions/checkout@v4
1922
- name: Set up Python ${{ matrix.python-version }}
@@ -30,11 +33,15 @@ jobs:
3033
npm install
3134
npm run build
3235
- name: Cleanup more disk space
33-
run: sudo rm -rf /usr/share/dotnet && sudo rm -rf /opt/ghc && sudo rm -rf "/usr/local/share/boost" && sudo rm -rf "$AGENT_TOOLSDIRECTORY"
36+
run: |
37+
sudo rm -rf /usr/share/dotnet
38+
sudo rm -rf /opt/ghc
39+
sudo rm -rf "/usr/local/share/boost"
40+
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
3441
- name: Install python dependencies
3542
run: |
3643
python -m pip install --upgrade pip
37-
pip install --upgrade flake8 pytest==8.0.1 pycodestyle
44+
pip install --upgrade flake8 pytest==8.3.5 pycodestyle
3845
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3946
- name: Lint with flake8
4047
run: |
@@ -48,8 +55,21 @@ jobs:
4855
python -m build
4956
- name: Test with pytest
5057
run: |
51-
pip install playwright==1.41.1 pytest-playwright==0.6.2 pytest==8.0.1 pytest-github-actions-annotate-failures pytest-cov==4.1.0
58+
pip install playwright==1.52.0 pytest-playwright==0.7.0 pytest==8.3.5 pytest-github-actions-annotate-failures pytest-cov==6.2.1
5259
playwright install chromium firefox
5360
pytest --cov=streamlit_pdf_viewer --cov-report xml
5461
- name: Coveralls
5562
uses: coverallsapp/github-action@v2
63+
with:
64+
flag-name: run ${{ join(matrix.*, ' - ') }}
65+
parallel: true
66+
67+
coveralls-finish-build:
68+
needs: [ build ]
69+
runs-on: ubuntu-latest
70+
71+
steps:
72+
- name: Coveralls
73+
uses: coverallsapp/github-action@v2
74+
with:
75+
parallel-finished: true

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ action [here](https://structure-vision.streamlit.app/).
3232

3333
- Tested and developed to support Firefox and Chrome.
3434
- The legacy visualization works only on Firefox and does not support annotations
35-
- Our JavaScript skills are limited, so all troubleshooting may take time
35+
- This is a side project, so all troubleshooting may take time
3636
- The component is still in development, so expect some bugs and limitations
3737
- The streamlit reload at each action may render slowly for complex PDF documents
38+
- Removed support showing PDF documents using the native pdf.js browser's viewer.
3839

3940
## Caveats
4041

41-
Here some caveats to be aware of:
42+
Here are some caveats to be aware of:
4243

4344
- It is mandatory to specify a `width` to show PDF document on tabs and expanders, otherwise, the viewer will not be
4445
displayed on tabs not immediately visible.
@@ -49,8 +50,7 @@ Here some caveats to be aware of:
4950
useful).
5051
- If you need to use all the available space and limit the height, you can encapsulate the `pdf_viewer()` into a
5152
`st.component(width:...)` setting the width.
52-
- The `legacy` rendering is not supported on Chrome, due to security reasons.
53-
53+
- The `legacy` rendering has been removed from version 0.1.x+
5454
## Getting started
5555

5656
```sh
@@ -95,7 +95,6 @@ In the following table the list of parameters that can be provided to the `pdf_v
9595
| annotations | A list of annotations to be overlaid on the PDF. Format is described [here](#annotation-format). |
9696
| pages_vertical_spacing | The vertical space (in pixels) between each page of the PDF. Defaults to 2 pixels. |
9797
| annotation_outline_size | Size of the outline around each annotation in pixels. Defaults to 1 pixel. |
98-
| 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: |
9998
| pages_to_render | Filter the rendering to a specific set of pages. By default, all pages are rendered. |
10099
| 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. |
101100
| zoom_level | The zoom level of the PDF viewer. Can be a float (0.1-10.0), `"auto"` for fit-to-width, `"auto-height"` for fit-to-height, or `None` (defaults to auto-fit to width). When zoom controls are enabled, users can interactively adjust the zoom level. |
@@ -207,9 +206,9 @@ correct directory before running these commands.
207206
npm run build
208207
```
209208

210-
1. Make sure that _RELEASE = True in `streamlit_pdf_viewer/__init__.py`.
209+
2. Make sure that _RELEASE = True in `streamlit_pdf_viewer/__init__.py`.
211210

212-
2. move to the streamlit_application and run
211+
3. move to the streamlit_application and run
213212

214213
```shell
215214
pip install -e {path of component}

streamlit_pdf_viewer/__init__.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
import json
88

99
_RELEASE = True
10-
RENDERING_EMBED = "legacy_embed"
11-
RENDERING_IFRAME = "legacy_iframe"
12-
RENDERING_UNWRAP = "unwrap"
1310

1411
if not _RELEASE:
1512
_component_func = components.declare_component(
@@ -33,7 +30,6 @@ def pdf_viewer(
3330
annotations: List[Dict[str, Union[str, int, float, bool]]] = [],
3431
pages_vertical_spacing: int = 2,
3532
annotation_outline_size: int = 1,
36-
rendering: str = RENDERING_UNWRAP,
3733
pages_to_render: List[int] = (),
3834
render_text: bool = False,
3935
resolution_boost: int = 1,
@@ -54,11 +50,7 @@ def pdf_viewer(
5450
:param annotations: A list of annotations to be overlaid on the PDF. Each annotation should be a dictionary.
5551
:param pages_vertical_spacing: The vertical space (in pixels) between each page of the PDF. Defaults to 2 pixels.
5652
:param annotation_outline_size: Size of the outline around each annotation in pixels. Defaults to 1 pixel.
57-
:param rendering: Type of rendering. The default is "unwrap", which unwrap the PDF. Other values are
5853
:param pages_to_render: Optional list of page numbers to render. If None, all pages are rendered. This allows for selective rendering of pages in the PDF.
59-
"legacy_iframe" and "legacy_embed" which uses the legacy approach for showing PDF document with streamlit.
60-
These methods enable the default pdf viewer of Firefox/Chrome/Edge that contains additional features we are still
61-
working to implement for the "unwrap" method.
6254
:param render_text: Whether to enable selection of text in the PDF viewer. Defaults to False.
6355
:param resolution_boost: Boost the resolution by a factor from 2 to 10. Defaults to 1.
6456
:param zoom_level: The zoom level of the PDF viewer. Can be a float (0.1-10.0), "auto" for fit-to-width, "auto-height" for fit-to-height, or None (defaults to auto-fit to width).
@@ -117,17 +109,12 @@ def pdf_viewer(
117109
else:
118110
binary = input
119111

120-
if rendering == RENDERING_IFRAME or rendering == RENDERING_EMBED:
121-
print(f"{RENDERING_IFRAME} and {RENDERING_EMBED} may not work consistently on all browsers "
122-
f"they might disappear in future releases.")
123-
if height is None:
124-
height = "100%"
125-
126112
if not isinstance(annotations, list):
127113
raise TypeError("annotations must be a list of dictionaries")
128114
if any(not isinstance(annotation, dict) for annotation in annotations):
129115
raise TypeError("annotations must be a list of dictionaries")
130116

117+
131118
base64_pdf = base64.b64encode(binary).decode('utf-8')
132119
component_value = _component_func(
133120
binary=base64_pdf,
@@ -138,7 +125,6 @@ def pdf_viewer(
138125
annotations=annotations,
139126
pages_vertical_spacing=pages_vertical_spacing,
140127
annotation_outline_size=annotation_outline_size,
141-
rendering=rendering,
142128
pages_to_render=pages_to_render,
143129
render_text=render_text,
144130
resolution_boost=resolution_boost,

0 commit comments

Comments
 (0)