Render PDFs inline in notebook cells#13844
Open
rodrigosf672 wants to merge 4 commits into
Open
Conversation
Route IPython.display.IFrame PDF outputs through the pdf-server extension's full pdf.js viewer, with an "Open With..." button for opening in alternative editors. Adds extractPdfIframeInfo as a tested utility for detecting PDF iframes in notebook HTML output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fold theme preference injection directly into the /pdfjs-notebook/web/viewer.html route handler, eliminating an unnecessary intermediate redirect page. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
E2E Tests 🚀 |
Use pdf.js webviewerloaded event to set theme options reliably instead of localStorage which races with pdf.js initialization.
Signed-off-by: Rodrigo Silva Ferreira <129895386+rodrigosf672@users.noreply.github.com>
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.
Closes #10606
Summary
IPython.display.IFramePDF outputs through the positron-pdf-server extension's full pdf.js viewerextractPdfIframeInfoas a tested utility for detecting PDF iframes in notebook HTML outputTest plan
IPython.display.IFrame('file.pdf', width=800, height=600)-- PDF renders inline with full pdf.js viewernpx vitest run src/vs/workbench/contrib/positronWebviewPreloads/browser/positronWebviewPreloadService.vitest.tspasses@:positron-notebooks @:notebooks @:win @:web
Remarks
Dark mode to the PDF when opened in the inline editor in the notebook is applied
Initially, there was a difference between dark in the PDF viewer vs. in the notebook. See difference below between Notebook vs. PDF editor preview behavior.
I've fixed it in the latest commit. Now, dark mode is consistent across the two PDF opening modes.
Known limitation
If notebook pane is reduced in width, the PDF action bar does not auto-scale well when PDF is inside the notebook. This is a known limitation that is difficult to be addressed.
Changes are only kept if saved (by design)
If user makes changes to the PDF inline and then 'Open With...' the PDF in the Viewer, PDF will be opened in the Viewer in unchanged state, since the user did not save the changes. This behaves this way to prevent pane conflict as well.
Multi-pane conflict prevention
I opened the notebook with the PDF next to a pane containing the PDF opened by the PDF Server Preview. Notice that actions performed in one pane are independent from actions performed in the PDF inside the notebook. This is important to work this way, to prevent pane conflicts.
Unit tests added
New tests added (under
describe('extractPdfIframeInfo')):.pdf src(standard case with width/height)IPython.display.IFrameoutput (double-quoted, absolute path)<iframe src="doc.pdf">)