Skip to content

feat(pdf-studio): PDF.js based viewer and editor - #618

Closed
AlexAndBear wants to merge 18 commits into
mainfrom
experimental/pdf-studio
Closed

AlexAndBear wants to merge 18 commits into
mainfrom
experimental/pdf-studio

Conversation

@AlexAndBear

@AlexAndBear AlexAndBear commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

📄 PDF Studio

Fill in, sign, mark up and rearrange PDFs in OpenCloud – everything is saved into the PDF itself: form values, signatures, annotations, comments and page changes, through OpenCloud's save button, Ctrl+S and versions (no autosave, so a form can be filled in just to print it). Reopen it here or in any other PDF reader and it's all there; password-protected files stay encrypted.

Built on the pdfjs-dist viewer components (web-app-pdf-studio), it shows up under "Open with" next to the built-in PDF viewer.

🎬 Demo

pdf-studio-demo.mp4

📱 On the phone

pdf-studio-mobile-demo.mp4

✨ Features

  • 📖 Viewing – zoom (incl. pinch), page layouts, rotation, thumbnails, page labels, search, presentation mode, hand tool, document properties
  • 📝 Forms – AcroForm and XFA, form scripts run in PDF.js' sandbox
  • ✍️ Signatures – draw, type or upload an image (from the device or the cloud); up to five saved for reuse
  • 🖍️ Annotations – highlights, text, drawings, images (also from OpenCloud), with tool settings
  • 💬 Comments – add, edit, delete, list of all comments
  • 🗂️ Pages & sidebar – delete and reorder pages with undo; outline, attached files and layers in the sidebar
  • 🖨️ Printing – with form values and annotations
  • 📱 Toolbar for every screen – a menu like the PDF.js viewer's for what doesn't fit; one row with touch gestures and bottom drawers on phones
  • 🎨 Native look – OpenCloud design system, light and dark theme, keyboard and screen reader support

🦊 Close to the PDF.js viewer

PDF Studio deliberately sticks to the PDF.js viewer that ships with Firefox: same tools, menus, shortcuts and behaviour, built with the OpenCloud design system.

  • Fewer design decisions – PDF.js has already worked out how these features behave, we don't reinvent them
  • Familiar – anyone using Firefox already knows how it works

Read-only shares and links get the viewer without editing tools.

🔮 Later

  • AppWrapper support for apps that need a moment to write their content (web#3718)

Known PDF.js limitations: some XFA values aren't saved, page operations drop layers and XMP metadata (pdf.js#22125), comments of e.g. underlines can't be changed.

🛠️ Under the hood

  • PDF.js assets (worker, sandbox, CMaps, fonts, wasm) are copied into dist/pdfjs, pdf_viewer.css is scoped to the app
  • PDF.js is only loaded once a PDF is opened
  • Changes are written via saveDocument() debounced; save and close wait for the latest content

@tbsbdr

tbsbdr commented Oct 9, 2026

Copy link
Copy Markdown
Member

awesome!!

@micbar

micbar commented Oct 9, 2026

Copy link
Copy Markdown
Member

Really awesome!

@AlexAndBear
AlexAndBear force-pushed the experimental/pdf-studio branch from a6d45f3 to c523e9f Compare October 9, 2026 16:12
@AlexAndBear AlexAndBear changed the title [experimental] feat(pdf-studio): PDF.js based viewer and editor feat(pdf-studio): PDF.js based viewer and editor Oct 9, 2026
@AlexAndBear
AlexAndBear force-pushed the experimental/pdf-studio branch 2 times, most recently from 89a2a4c to 2cd53ef Compare October 9, 2026 19:34
@AlexAndBear
AlexAndBear marked this pull request as ready for review October 9, 2026 19:50
@AlexAndBear

AlexAndBear commented Oct 9, 2026 •

Copy link
Copy Markdown
Member Author

Note: It's too easy to accidentally move or delete a page with a single click while scrolling through the pages in the sidebar. We need a better UI concept for the page actions.

-> 3 Dot Menu ✅

A new app for viewing and editing PDFs, built on the pdfjs-dist viewer components.
- PDF.js' worker, form sandbox, CMaps, fonts, ICC profiles and wasm decoders are copied into
  dist/pdfjs, nothing is loaded from elsewhere. pdf_viewer.css is scoped to the app.
- Loading documents, also password-protected ones, with load errors and retry.
- PDF.js' texts translated with the app's translations.
Comments on selected text, highlights, drawings and images, a list of all comments of the
document, popups to read, edit and delete them. Comments of other tools (e.g. Acrobat) are
shown, rich text in the size and colors of OpenCloud.
Like the PDF.js viewer: page navigation, zoom (also pinching and Ctrl + wheel), scroll and
spread modes, rotation, find bar, keyboard shortcuts, printing with forms and annotations,
presentation mode, hand tool, document properties and page labels.
Thumbnails, document outline, attachments and layers in the sidebar, opened like the PDF asks
for. Pages can be moved and deleted from a menu per page, with undo and redo.
Highlights, text, drawings and images (from the device or from OpenCloud) with the settings
of the PDF.js viewer, alt texts, and signatures (typed, drawn or from an image), up to five
saved for reuse. A tool picker on phones.
Form values, annotations and comments are tracked and written into the file, for
OpenCloud's save, Ctrl+S and autosave. Form scripts run before saving, saving failures of
PDF.js are reported instead of saving stale content.
A toolbar in the order of the PDF.js viewer with a "More actions" menu for what doesn't fit,
one row with bottom drawers on phones. The app opens PDFs in OpenCloud ("Open with"), also on
public links, read-only files get the viewer without editing tools. End-to-end tests.
@AlexAndBear
AlexAndBear force-pushed the experimental/pdf-studio branch from 75b0f14 to 72cecda Compare October 10, 2026 14:21
Squash of the follow-ups after the feature commits:

- Review follow-ups: AppWrapper's register:onSaveCallback (web 8.1.0) instead of the etag
  watch, page number as oc-text-input, auto zoom for the page shown after page operations,
  the comments drop mounted together with its toggle, the signature dialog in the style of
  the design system.
- Exploratory tests: single-key shortcuts don't reach the host (s), the find bar keeps the
  current match when reopened and doesn't highlight all by default, XFA forms print one page
  per sheet, typing goes on after Ctrl+S, the password prompt takes no empty password and
  shows the error in its input, comment popups stay clear of the list of comments, forced
  colors for swatches and active menu items, dirty state after a quick undo.
- UX: the viewed page stays when deleting another page, authors of saved annotations in
  comment popups and the list, the list also has the comments of annotations PDF.js has no
  editor for (sticky notes, underlines, attachments), the drop of saved signatures fits
  the descriptions, cancelling the password prompt closes the app, a wrong password keeps
  the same prompt open.
- Code review: comments of annotations that are their own trigger open from the list, the
  comments of a document are looked up once, a search without matches stays marked while
  the find bar is closed, PDF.js' editor toolbars keep their keys, deleting a page takes
  the page viewed once pending changes are written.
- Simplification review: view options and signature options folded into their only users,
  computedAsync for saved signatures, the L10n object reduced to what PDF.js calls, dead
  guards and duplicate tests removed, the PDF.js polyfill as vitest setup file.
- README: tool settings, dirty state of form values, password prompt.
@AlexAndBear
AlexAndBear force-pushed the experimental/pdf-studio branch from a4c7fb0 to f20ce91 Compare October 11, 2026 08:16
@AlexAndBear

AlexAndBear commented Oct 11, 2026 •

Copy link
Copy Markdown
Member Author

PDF.js issues reported while building this.

Visible to users of PDF Studio:

Worked around in PDF Studio (listed so the workaround can go once PDF.js fixes it):

@AlexAndBear
AlexAndBear force-pushed the experimental/pdf-studio branch from 62def5f to f20ce91 Compare October 11, 2026 14:22
…y on phones

The tool picker showed them in a section of their own below all tools, far down in the
drawer for the drawing tool. Now they follow the entry of the active tool like a sub menu,
framed in the color of the entry, with the same spacing on all sides.
- Typing on after Ctrl+S: the text box is back in edit mode before the save runs, so no
  key is lost to the page, and the caret stays where it was when PDF.js moves the committed
  editor in the DOM a moment later.
- A drawing counts as a change from its first stroke, not only once the pointer is released;
  dragging a selected annotation (which disables text selection the same way) does not.
- A new image counts as a change while it decodes (PDF.js marks its layers as waiting), and
  a save in that window waits for the image instead of doing nothing.
- README: PDF.js offers comments on new drawings, texts and images, not on saved ones.
@AlexAndBear
AlexAndBear force-pushed the experimental/pdf-studio branch 2 times, most recently from d7aba33 to 6f57bd5 Compare October 11, 2026 16:21
- Icons like in the preview app and the text editor: the sidebar toggle uses the preview's
  side-bar icon (filled while open), rotating its clockwise/anticlockwise icons, the find
  button the text editor's search icon, adding an image from the device its image icon.
- Toolbar spacing like the text editor: 4 px between buttons and groups, and the separators
  between groups are visible again (bg-role-border doesn't exist as a background color,
  they are borders now).
@AlexAndBear
AlexAndBear force-pushed the experimental/pdf-studio branch from 6f57bd5 to 7be1f99 Compare October 11, 2026 16:51
Forms are often only filled in to print them, an autosave would change the file meanwhile.
Saving stays with the save button, Ctrl+S and the question when closing.
@AlexAndBear

AlexAndBear commented Oct 11, 2026 •

Copy link
Copy Markdown
Member Author

@kulmann @tbsbdr heads-up: I disabled autosave for PDF Studio (disableAutoSave: true on the AppWrapperRoute, commit "feat(pdf-studio): no autosave").

Why: quite often you open a PDF form just to fill it in and print it, without wanting to change the file in the cloud. With autosave the filled-in values would end up in the file after two minutes without asking. Saving still works as usual via the save button, Ctrl+S and the "unsaved changes" question when closing.

This is a product decision on my side, happy to hear other opinions 🎀

@AlexAndBear
AlexAndBear force-pushed the experimental/pdf-studio branch from c1aaeaf to 5202124 Compare October 11, 2026 18:13
- Printing renders all pages on one canvas and waits only until each page image is loaded,
  like the PDF.js viewer: about a third faster for long documents.
- The page undo keeps up to 50 MB of file versions on touch devices instead of 200 MB, they
  have far less memory for a tab.
- Changes of large files are written after the same short delay as others, PDF.js saves
  incrementally and takes well under a second even for big scans.
@AlexAndBear
AlexAndBear force-pushed the experimental/pdf-studio branch 3 times, most recently from 91dbfed to 7ca5486 Compare October 11, 2026 19:45
- Inside the image area of the signature dialog, "Or pick from cloud" opens OpenCloud's file
  picker on top of the dialog, like for images of annotations; not on public links, where the
  picker only shows the shared files.
- The save switch explains that saved signatures are kept in this browser only, unless the
  limit of saved signatures is reached, which it explains instead.
@AlexAndBear
AlexAndBear force-pushed the experimental/pdf-studio branch 4 times, most recently from 110f39f to fc5a47c Compare October 11, 2026 21:09
…ight sidebar

- The document properties are a panel of OpenCloud's right sidebar instead of a dialog,
  next to details, shares and versions. The entry in the more menu opens the sidebar on it.
  It follows the current page and rotation like in the PDF.js viewer, and is only offered
  for the open document, not in the sidebar of the files app.
- The properties are grouped in boxes like the user settings in the admin settings, with
  OpenCloud's definition list.
- The README is shorter and mentions the panel.
@AlexAndBear
AlexAndBear force-pushed the experimental/pdf-studio branch from fc5a47c to bb85665 Compare October 11, 2026 21:09
- e2e tests for highlights, undo/redo, moving pages, the unsaved-changes prompt, editing and
  deleting comments, zoom, rotation, the hand tool, outline/attachments/layers, read-only
  links, images and their descriptions, signature descriptions, printing, presentation mode,
  password-protected files and sticky notes, with three small generated fixtures.
- Contract tests against PDF.js' code: what it uses of the comment, signature and alt text
  managers, the text ids of the translations and the class names the app looks for.
- Broken outlines, attachments, page labels, layers, page modes and metadata in a file are left
  out instead of loading forever.
- Follow-ups of the architecture review: zoom gestures and the form field commit in their own
  composables, one placement map for toolbar and "More actions" menu, `editing` as one object.
- The shared upload helper waits for its menu to open and close, it stayed open sometimes.
@AlexAndBear

AlexAndBear commented Oct 16, 2026 •

Copy link
Copy Markdown
Member Author

Plan before rolling out PDF Studio more widely

  1. Update to the next PDF.js release (estimated 31 October–7 November 2026, based on the release cadence) and remove workarounds for the fixes it includes.
  2. Decide where PDF Studio should live: keep it as an extension or use it to replace the PDF viewer directly in OpenCloud Web. If it replaces the built-in viewer, keep the PDF Studio name ?
  3. While waiting, fix the top-bar Save button. PDF Studio needs time to prepare the PDF for saving, and the button currently stays clickable long enough to be pressed repeatedly. Show that saving is in progress and prevent further save requests until preparing and saving the file have finished (AppWrapper: let apps bring their content up to date before saving web#3718).

Remove the workarounds for PDF.js issues fixed in this release:

- mozilla/pdf.js#22121: use the minified scripting sandbox again
- mozilla/pdf.js#22212: dispatchWillSave() now waits for the WillSave
  scripts, no extra task needed before saving

createScripting stays, PDF.js passing on the sandbox events itself
(mozilla/pdf.js#22133 is fixed) would bypass usePdfFormFieldCommit.
@AlexAndBear

Copy link
Copy Markdown
Member Author

Closing this one, we're moving PDF Studio into core instead: it replaces the built-in PDF viewer in opencloud-eu/web#4614 (same app name and icon as the old viewer).

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.

3 participants