Skip to content

Render PDFs inline in notebook cells#13844

Open
rodrigosf672 wants to merge 4 commits into
mainfrom
pdf-notebook-inline
Open

Render PDFs inline in notebook cells#13844
rodrigosf672 wants to merge 4 commits into
mainfrom
pdf-notebook-inline

Conversation

@rodrigosf672
Copy link
Copy Markdown
Member

@rodrigosf672 rodrigosf672 commented May 28, 2026

Closes #10606

Summary

  • Route IPython.display.IFrame PDF outputs through the positron-pdf-server extension's full pdf.js viewer
  • Add "Open With..." button in the notebook viewer's secondary toolbar to open the PDF in an alternative editor
  • Extract extractPdfIframeInfo as a tested utility for detecting PDF iframes in notebook HTML output

Test plan

  • Open a notebook, run IPython.display.IFrame('file.pdf', width=800, height=600) -- PDF renders inline with full pdf.js viewer
  • Click "Open With..." in secondary toolbar -- editor picker dialog appears without auto-opening the file (this is to allow PDF to be opened from the notebook into existing extensions that the user may prefer as well)
  • Verify theme (light/dark) is applied correctly to the inline viewer (fixed in latest commit)
  • Verify existing PDF editor preview (opening .pdf from Explorer) still works unchanged
  • npx vitest run src/vs/workbench/contrib/positronWebviewPreloads/browser/positronWebviewPreloadService.vitest.ts passes

@: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.

image

I've fixed it in the latest commit. Now, dark mode is consistent across the two PDF opening modes.

image

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.

image

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.

image

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.

image

Unit tests added

New tests added (under describe('extractPdfIframeInfo')):

  1. detects an iframe with a .pdf src (standard case with width/height)
  2. detects IPython.display.IFrame output (double-quoted, absolute path)
  3. handles single-quoted attributes (single quotes around src/width/height)
  4. returns src only when width/height are absent (bare <iframe src="doc.pdf">)
  5. returns undefined for non-PDF iframes (.html src is ignored)
  6. returns undefined for HTML without iframes (plain HTML, no iframe at all)
  7. is case-insensitive on the .pdf extension (.PDF uppercase works)

rodrigosf672 and others added 2 commits May 27, 2026 22:31
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>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:positron-notebooks @:notebooks @:win @:web

readme  valid tags

rodrigosf672 and others added 2 commits May 28, 2026 09:20
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>
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.

PDFs should be rendered as IFrame via IPython.display

1 participant