Skip to content

#210 Limit imported PDF size in Document Editor - #210

Merged
0mar-K merged 2 commits into
masterfrom
omar/document-editor-import-size-limit
Nov 13, 2026
Merged

0mar-K merged 2 commits into
masterfrom
omar/document-editor-import-size-limit

Conversation

@0mar-K

@0mar-K 0mar-K commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds a Playground example that swaps the Document Editor's Import Document button for an Import PDF button that turns away PDFs over 25 MB before they're staged. The limit lives in MAX_FILE_SIZE_MB (1 MB is 1024 × 1024 bytes). Files the browser doesn't report as application/pdf get rejected too, like the built-in button does.

Like the built-in button, it stages the import with treatImportedDocumentAsOnePage: true and beforePageIndex: 0 when no page is selected. With pages selected it goes after the last selected one, while the built-in button inserts at the start when two or more are selected.

The size check only runs on this button. The drag-and-drop-files-ui example has no size check.

It needs 1.18.0 or later. On 1.9.1 and 1.17.0, a custom button's setOperations also applies edits the user undid, so Rotate, Undo, then Import kept the rotation and dropped the import, while the built-in button didn't. On 1.18.0 and 1.25.0 both buttons give the same result.

Tested clicking Save each time. In the Playground (1.25.0) with playground.url, a 2-page PDF got imported, and a 27,000,668-byte one showed "This PDF is 25.8 MB. You can import PDFs up to 25 MB." and added nothing. Locally on 1.18.0 and 1.25.0 with the same code, a PDF of exactly 26,214,400 bytes got imported and one byte more got rejected. Imports landed after the last selected page, two imports in a row with nothing selected landed in the same order as with the built-in button on 1.25.0, importing after deleting the last two pages saved without errors, rotating the page after the imported one rotated that page, a text file showed "The file must be a PDF." and added nothing, and Rotate, Undo, then Import left no rotation and kept the import.

Type

  • New playground snippet
  • New local example
  • New external link / resource
  • Update to existing content
  • Repo infrastructure (CI, docs, tooling)

Checklist

  • npm run format passes and leaves this PR's files unchanged. biome ci . and npm run typecheck in playground/ pass too.
  • README/index updated where needed (category index and/or root README). Added to playground/web-document-editor.md, which the root README already links.
  • Example has a README.md with description and quick start (if local example). Not applicable, this is a Playground snippet.
  • Local example documents its run command and runs successfully with its documented script (if local example). Not applicable, this is a Playground snippet.
  • No duplicate content (not both playground snippet and local example for the same use case). Playground snippet only, with no local example for the same use case.

@0mar-K 0mar-K changed the title Limit imported PDF size in Document Editor #210 Limit imported PDF size in Document Editor Nov 13, 2026
@0mar-K
0mar-K marked this pull request as ready for review November 13, 2026 14:09
@0mar-K
0mar-K requested review from a team as code owners November 13, 2026 14:09

@miguelcalderon miguelcalderon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The size checks look good. Please address the Undo → Import case before merging.

};

// Stage the import. It's applied when the user saves.
handler.setOperations((operations) => operations.push(operation), true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the SDK pinned here (1.9.1), Rotate → Undo → Import leaves the rotation active and the new PDF out of Save. setOperations keeps the undone edits, unlike the built-in importer. Please preserve the built-in undo behavior, or document a verified minimum SDK version, and check this sequence on 1.25.0 too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Rotate, Undo, Import on 1.9.1 and 1.17.0 keeps the rotation and drops the import with this button, while the built-in one doesn’t. On 1.18.0 and 1.25.0 both give the same result, so I added a 1.18.0 minimum to the example’s comment and the PR description

@0mar-K
0mar-K merged commit 182aefd into master Nov 13, 2026
3 checks passed
@0mar-K
0mar-K deleted the omar/document-editor-import-size-limit branch November 13, 2026 16:39
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.

2 participants