Skip to content

Add Zoom Controls, Alignment Options & Page-Separator Support#103

Merged
lfoppiano merged 11 commits into
ScienciaLAB:mainfrom
danieljannai:add-zoom-alignment-separators
Jun 23, 2025
Merged

Add Zoom Controls, Alignment Options & Page-Separator Support#103
lfoppiano merged 11 commits into
ScienciaLAB:mainfrom
danieljannai:add-zoom-alignment-separators

Conversation

@danieljannai

Copy link
Copy Markdown

This PR introduces three ergonomic improvements to streamlit-pdf-viewer:

  1. Interactive Zoom
    zoom_level accepts float, "auto", "auto-height" or None (default = fit-to-width).
    • Top-right dropdown with presets, ± buttons and manual entry.

  2. Viewer Alignment
    viewer_align="left" | "center" | "right" (default = center).

  3. Optional Page Separators
    show_page_separator=True | False.


Additional updates

  • README – feature list, parameter table and usage example updated.
  • New e2e tests – 32 tests across Firefox & Chromium cover the new functionality; all pass locally.

No existing behaviour is changed; any failing CI checks stem from pre-existing legacy-mode tests.

…ameter with support for numeric values, 'auto', and 'auto-height' - Add viewer_align parameter for left/center/right alignment - Add show_page_separator parameter for optional horizontal lines between pages - Implement zoom controls with manual input, preset levels, and fit options - Add input validation and race condition protection for zoom functionality - Include example file demonstrating new features
…st files for zoom functionality (numeric, auto, auto-height) - Add separate test files for alignment functionality (left, center, right) - Add separate test files for page separator functionality (enabled/disabled) - Each test includes corresponding example Streamlit app for demonstration - Tests cover basic rendering, functionality verification, and visual positioning - Replace combined example with focused individual test cases
…ctors from id to class (.zoom-button) - Fix zoom control button text selectors (Zoom In/Zoom Out) - Update page separator tests to check CSS border styles instead of separate elements - Fix zoom_level parameter in auto zoom example (use None instead of 'auto') - 22/32 tests now passing
…l validation to allow string values ('auto', 'auto-height') - Update alignment positioning tests to check computed margin values instead of CSS 'auto' - Use realistic positioning assertions for center/right alignment - All zoom functionality tests: 12/12 ✅ - All alignment functionality tests: 12/12 ✅ - All page separator tests: 8/8 ✅ - Total: 32/32 tests passing across Firefox and Chromium browsers
…for precise constraints - Fix zoom_level, viewer_align, and rendering parameter types - Add Optional[] for nullable parameters - Add return type annotation - Update docstring for zoom_level parameter
@lfoppiano

Copy link
Copy Markdown
Collaborator

@danieljannai Thanks!! That's great someone implemented such a big feature. 🚀
I'm going to revise ASAP. @t29mato could you please also double check it?

@lfoppiano
lfoppiano requested a review from Copilot June 21, 2025 06:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces three new ergonomic features to the PDF viewer component: interactive zoom controls, configurable viewer alignment, and optional page separators. Key changes include adding multiple zoom options (numeric values, "auto", and "auto-height"), aligning the viewer via a new parameter, and conditionally rendering horizontal separators between pages, with corresponding tests and documentation updates.

Reviewed Changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated 1 comment.

File Description
tests/* New e2e tests covering zoom controls, auto zoom variants, page separator visibility, and viewer alignment
streamlit_pdf_viewer/frontend/src/PdfViewer.vue Updated component template and script to include zoom controls, alignment logic, and page separator styling
streamlit_pdf_viewer/init.py Updated parameter defaults and validations for zoom_level, viewer_align, and show_page_separator, with adjusted documentation
README.md Documentation updated to reflect new features and options
Comments suppressed due to low confidence (1)

streamlit_pdf_viewer/init.py:39

  • There is a spelling error in the printed message: 'disapper' should read 'disappear'.
        resolution_boost: int = 1,

Comment thread streamlit_pdf_viewer/__init__.py Outdated
@lfoppiano

lfoppiano commented Jun 21, 2025

Copy link
Copy Markdown
Collaborator

HI @danieljannai, you did a terrific job. 🚀

I have one question, what is the show_page_separator as compared with the option pages_vertical_spacing. I wonder if we could merge them into one option to make it simpler.

More generally, I'm also wondering whether we could get rid of all the legacy stuff which are just a pain to maintain.

@danieljannai

Copy link
Copy Markdown
Author

Thanks @lfoppiano, just extended your terrific work 😄

The main idea behind show_page_separator was to have a visual cue of where one page ends and another ones starts, especially in multi-page documents with white background where it can be unclear. Not sure how to merge it with the pages_vertical_spacing parameter, to be honest. You could add a "separation config" but it feels like an overkill. What do you have in mind?

With regards to legacy stuff, I 100% agree. It might be a breaking change, but it's necessary. Especially since many tests don't pass at the moment.

@danieljannai

Copy link
Copy Markdown
Author

@lfoppiano
I thought it would be really useful to allow full installation of the package (including the npm run build step) directly from GitHub. Are you okay with me adding it to this PR?

@lfoppiano

Copy link
Copy Markdown
Collaborator

Separating config looks a bit too complicated, indeed.

I would just like to make sure those two options don't clash:

  • if show_page_separator = False, it's the same as pages_vertical_spacing = 0 (any other value will be ignored, and we should warn the user if they have them set)
  • if show_page_separator = True, it's the same as pages_vertical_spacing = 1 or 2 (the default page separation)

Regarding the legacy rendering, we can release 0.1.0 and break compatibility. I think there is already a PR #96

@lfoppiano

Copy link
Copy Markdown
Collaborator

@lfoppiano I thought it would be really useful to allow full installation of the package (including the npm run build step) directly from GitHub. Are you okay with me adding it to this PR?

Sure! 🎉

@lfoppiano lfoppiano linked an issue Jun 22, 2025 that may be closed by this pull request
@danieljannai

Copy link
Copy Markdown
Author

Separating config looks a bit too complicated, indeed.

I would just like to make sure those two options don't clash:

  • if show_page_separator = False, it's the same as pages_vertical_spacing = 0 (any other value will be ignored, and we should warn the user if they have them set)
  • if show_page_separator = True, it's the same as pages_vertical_spacing = 1 or 2 (the default page separation)

Regarding the legacy rendering, we can release 0.1.0 and break compatibility. I think there is already a PR #96

They don't seem to clash. Take a look at the attached screenshots:

  1. show_page_separator=True (default) and pages_vertical_spacing=2 (default). Note that there's a thin grey line, below it two white pixel rows and only then the light-blue stripe at the top of the second page:
    image
  2. show_page_separator=False and pages_vertical_spacing=2 (default). Note that the thin grey line is gone, but there are still two white pixel rows and only then the light-blue stripe at the top of the second page:
    image
    It might be easier to note in this example where the first page is all red, second one is all blue. Note the white gap between them:
    image
  3. show_page_separator=True (default) and pages_vertical_spacing=0. Note that there's a thin grey line between the pages:
    image
  4. show_page_separator=False and pages_vertical_spacing=0. Note that the thin grey line between the pages is gone:
    image

@danieljannai

Copy link
Copy Markdown
Author

@lfoppiano Added the auto-build during setup :)

@lfoppiano
lfoppiano merged commit fb7036b into ScienciaLAB:main Jun 23, 2025
1 of 13 checks passed
@lfoppiano

Copy link
Copy Markdown
Collaborator

I'm going to merge and release 0.0.26, then dump the legacy stuff and release 0.1.0 🎉
I'd keep some bug fixing on the branch 0.0 for a bit before decommissioning completely

@lfoppiano lfoppiano mentioned this pull request Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow zooming of pdf in streamlit interface

4 participants