Add PDF document viewer component with outline, pages, zoom, search, and print#626
Merged
Conversation
Member
Author
|
Does this appear to be missing anything @rebeccamccabe? |
There was a problem hiding this comment.
Pull request overview
This PR replaces basic <embed>-based PDF rendering with a shared PdfDocumentViewer component (built on react-pdf-highlighter / pdf.js) to give Publications and Files the richer PDF navigation experience already available elsewhere (outline/sections, page jump, zoom, search, print, open/download) while preserving annotation/highlighting support.
Changes:
- Added
PdfDocumentViewerwith toolbar controls (outline, paging, zoom, search, print, open/download) and optional highlight/selection integration. - Switched Publications and Files PDF rendering from
<embed>toPdfDocumentViewer. - Refactored
PdfAnnotatorto delegate PDF rendering/navigation toPdfDocumentViewerwhile keeping comment/highlight behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| frontend/src/components/Publications/PublicationView.tsx | Uses shared PDF viewer instead of <embed> for publication PDFs. |
| frontend/src/components/Publications/PdfAnnotator.tsx | Delegates PDF rendering/navigation to the shared viewer; keeps annotation integration via props. |
| frontend/src/components/Files/FileContent.tsx | Uses shared PDF viewer for PDF files instead of <embed>. |
| frontend/src/components/Common/PdfDocumentViewer.tsx | New shared PDF viewer implementing outline, paging, zoom, search, print, and open/download + optional highlighting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+155
to
+169
| <Text | ||
| fontSize="xs" | ||
| py={0.5} | ||
| noOfLines={2} | ||
| cursor={node.pageNumber ? "pointer" : "default"} | ||
| color={ | ||
| node.pageNumber && node.pageNumber === currentPage | ||
| ? "ui.main" | ||
| : undefined | ||
| } | ||
| _hover={node.pageNumber ? { color: "ui.main" } : undefined} | ||
| onClick={() => node.pageNumber && onSelect(node.pageNumber)} | ||
| > | ||
| {node.title} | ||
| </Text> |
Comment on lines
+643
to
+645
| }, [pdfDocument]) | ||
|
|
||
| const runSearch = useCallback( |
Comment on lines
+646
to
+670
| async (q: string) => { | ||
| const term = q.trim().toLowerCase() | ||
| if (!term) { | ||
| setMatchPages([]) | ||
| setMatchIdx(0) | ||
| return | ||
| } | ||
| setSearching(true) | ||
| try { | ||
| const pages = await ensureTextIndex() | ||
| const hits: number[] = [] | ||
| pages.forEach((text, i) => { | ||
| if (text.includes(term)) hits.push(i + 1) | ||
| }) | ||
| setMatchPages(hits) | ||
| setMatchIdx(0) | ||
| if (hits.length > 0) goToPage(hits[0]) | ||
| mixpanel.track("Searched PDF", { | ||
| source, | ||
| query_length: term.length, | ||
| num_matching_pages: hits.length, | ||
| }) | ||
| } finally { | ||
| setSearching(false) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #625
Did not use the embedded viewer so we could retain highlighting/commenting, but this should provide the desired features.