Skip to content

feat(pdf-viewer): view, annotate and edit PDFs based on PDF.js - #4614

Merged
AlexAndBear merged 3 commits into
mainfrom
feat/pdf-viewer-studio
Nov 26, 2026
Merged

AlexAndBear merged 3 commits into
mainfrom
feat/pdf-viewer-studio

Conversation

@AlexAndBear

@AlexAndBear AlexAndBear commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Description

The PDF viewer now uses PDF.js instead of the browser's built-in PDF view. This is the PDF Studio app from web-extensions, moved into core instead of shipping as an extension. Name, app id and icon of the PDF viewer stay the same.

What you get on top of plain viewing:

  • Viewing: page labels, zoom, rotation, scroll and spread modes, search, printing, presentation mode, and a sidebar with pages, outline, attachments and layers. It looks the same in every browser and follows the OpenCloud theme.
  • Editing: fill in forms (AcroForm and XFA), add highlights, text, drawings, images (from the device or the cloud) and signatures, comment on things, and delete or reorder pages. Changes get saved back into the PDF with the save button or Ctrl+S. There's no autosave, because forms are often only filled in to print them. Read-only access shows no editing tools, but viewers can still fill in forms to print them (nothing gets saved). @kulmann that's a product call, so shout if you see it differently.
  • Document properties: a panel in the right sidebar.
  • Same as Firefox's PDF viewer: we compared it feature by feature with the PDF.js viewer in Firefox and closed the gaps (e.g. undo toast, F3, high contrast colors, signature thickness). Where PDF.js itself has a limitation that Firefox has too, we behave the same instead of working around it.

Things worth knowing:

  • Startup: PDF.js only loads when a PDF is opened.
  • Assets: everything PDF.js needs comes from our own server, nothing from a CDN, and after an update no old cached worker gets picked up.
  • Browser support: we use the legacy PDF.js build, which polyfills most of what newer browsers have. It still needs Promise.withResolvers (Chrome 119, Firefox 121, Safari 17.4). Older browsers from our browserslist (roughly 2.7%, e.g. iOS 15.6 to 17.3) can't open PDFs anymore, where the old native view worked. We decided to accept that for now. @kulmann, your call if you see it differently.
  • No form scripts, no WebAssembly: this is a deliberate security decision. PDFs are untrusted content, so JavaScript inside them never runs, and PDF.js runs without WebAssembly so we don't have to loosen the CSP for it. The viewer behaves the same under any CSP. Forms can still be filled in, saved and printed, but calculated fields, script formatting and validation don't work. JPEG 2000 and JBIG2 images decode a bit slower, and ICC color profiles aren't applied.
  • Saving: the PDF only gets written when you save (or download, or close), so editing big PDFs stays fast.
  • Saved signatures: kept only while the PDF viewer is open, never in the browser storage, so on a shared computer the next user doesn't get them. Firefox keeps them in local storage, so this one differs on purpose.
  • Attachments and signature images: files embedded in a PDF are always downloaded, never opened in the browser. Signatures can be made from normal image files (PNG, JPEG, WebP, …) but not from SVG, since an SVG can contain scripts. Both for security reasons, same as above.

Related Issue

How Has This Been Tested?

  • test environment: unit tests (Vitest), browser tests (Playwright) against a local OpenCloud, Chromium desktop and Pixel 7 viewport
  • test case 1: unit: the app's specs (597 tests), against the legacy PDF.js build
  • test case 2: browser: open from the file list, "Open with" lists the PDF viewer once
  • test case 3: browser: highlight, free text and drawing, save with the button and Ctrl+S, reopen, unsaved changes prompt
  • test case 4: browser: fill in text, checkbox, radio and choice fields, save, reopen and print; forms with scripts stay fillable without running them; document properties panel
  • test case 5: browser: public view and edit links, read-only share without editing tools, viewers can fill in forms and print them without anything being saved
  • test case 6: browser: light and dark theme, no PDF.js styles left after closing the viewer
  • test case 7: browser: no PDF.js code loaded before a PDF is opened, all runtime files load from pdfjs/<version>/
  • test case 8: browser: no sandbox or wasm files are requested, JPEG 2000 and JBIG2 images render; attachments download in Chromium and Firefox; signatures from PNG/AVIF, SVG rejected; big PDF: no document write while editing, one per save
  • test case 9: browser: side by side with Firefox's built-in PDF.js viewer (navigation, zoom, find, sidebar, forms, editing tools, signatures, links, password and XFA PDFs), then the added features: undo toast, save → undo → redo back to unchanged, F3 and Escape in the find bar, mailto/tel links without an empty tab, forced colors, signature thickness
  • test case 10: browser: behaves like Firefox where PDF.js has known limitations: comments list contents, editing comments of underlines and sticky notes, dialogs, page operations with form values and encrypted PDFs (incl. undo/redo), the selection toolbar over form fields

Types of changes

  • Bugfix
  • Enhancement (a change that doesn't break existing code or deployments)
  • Breaking change (a modification that affects current functionality)
  • Technical debt (addressing code that needs refactoring or improvements)
  • Tests (adding or improving tests)
  • Documentation (updates or additions to documentation)
  • Maintenance (like dependency updates or tooling adjustments)

@codacy-production

codacy-production Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 high · 3 medium · 22 minor

Alerts:
⚠ 26 issues (≤ 0 issues of at least minor severity)

Results:
26 new issues

Category Results
BestPractice 2 medium
ErrorProne 1 high (1 false positive)
CodeStyle 17 minor
Complexity 1 medium
5 minor

View in Codacy

🟢 Metrics 2183 complexity · 10 duplication

Metric Results
Complexity 2183
Duplication 10

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@AlexAndBear
AlexAndBear marked this pull request as draft November 24, 2026 10:50
@AlexAndBear
AlexAndBear force-pushed the feat/pdf-viewer-studio branch from 6d53069 to 5d53edd Compare November 24, 2026 13:05
@AlexAndBear
AlexAndBear marked this pull request as ready for review November 24, 2026 13:05
@AlexAndBear
AlexAndBear force-pushed the feat/pdf-viewer-studio branch 2 times, most recently from 1e78fa6 to ebaa9ab Compare November 25, 2026 08:05
@AlexAndBear

Copy link
Copy Markdown
Member Author

Why we stay on the legacy PDF.js build: I tried switching to the modern build. The legacy build is the exact same code plus a core-js polyfill block in front, nothing else differs.

Without those polyfills, the modern build calls brand new builtins unguarded:

  • Map.prototype.getOrInsertComputed when opening a PDF: Chrome 145 (Feb 2026), Firefox 144, Safari 26.2
  • Math.sumPrecise when saving: Chrome 147 (around Apr 2026), Firefox 137, Safari 26

So with the modern build a Chrome from before February 2026 couldn't open PDFs at all, and one from before April couldn't save. The legacy build only needs Chrome 119 / Firefox 121 / Safari 17.4. Doing our own polyfills on top of the modern build would just rebuild the legacy build, and we'd have to track new builtins on every PDF.js update, so the legacy build it is.

@JammingBen

JammingBen commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

That's quite the feature set, nice. I haven't looked at the code too close yet, but 2 things I noticed:

  • Saved signatures leak into other accounts within the same tab. I think we should wait for user settings so we can safely store signatures.
  • Most toolbar actions are not available on mobile. I thought they would go into the 3-dots-menu on the right like in tiptap, but they're just gone. NVM I just overlooked them.

@AlexAndBear

Copy link
Copy Markdown
Member Author

They are kept now until the app is closed, opting out for user setting strategy for later

@AlexAndBear
AlexAndBear force-pushed the feat/pdf-viewer-studio branch from c149031 to b3faabf Compare November 26, 2026 03:59
Replace the PDF viewer with a viewer and editor built on PDF.js (pdfjs-dist,
legacy build), keeping its name and icon.

- View: thumbnails, outline, attachments, layers, find, page labels, zoom,
  rotation, scroll and spread modes, presentation mode, document properties,
  print and download, the keyboard shortcuts of the PDF.js viewer
- Edit: forms, text, highlights, drawings, images, signatures and comments,
  with undo/redo; delete and move pages
- Save through AppWrapper's flush hook, the PDF is only written on save
- PDF.js assets are copied to pdfjs/<version>/, its CSS is scoped to the viewer
- No form scripts and no WebAssembly, attachments are always downloaded,
  signatures only from raster images

Assisted-by: Claude Code:claude-opus-5-5
@AlexAndBear
AlexAndBear force-pushed the feat/pdf-viewer-studio branch from 5fad0ab to a64c0de Compare November 26, 2026 04:09
Viewers can fill in form fields, so they can print a filled form. Nothing
gets saved and nothing else changes for them. Escape in a form field no
longer closes the app, so what was filled in is not lost.

Assisted-by: Claude Code:claude-opus-5-5

@JammingBen JammingBen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@AlexAndBear
AlexAndBear merged commit 0a1d4e7 into main Nov 26, 2026
29 of 30 checks passed
@AlexAndBear
AlexAndBear deleted the feat/pdf-viewer-studio branch November 26, 2026 13:53
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in OpenCloud Team Board Nov 26, 2026
@openclouders openclouders mentioned this pull request Nov 26, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants