Repository navigation
#210 Limit imported PDF size in Document Editor - #210
Conversation
miguelcalderon
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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 asapplication/pdfget rejected too, like the built-in button does.Like the built-in button, it stages the import with
treatImportedDocumentAsOnePage: trueandbeforePageIndex: 0when 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-uiexample has no size check.It needs 1.18.0 or later. On 1.9.1 and 1.17.0, a custom button's
setOperationsalso 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
Checklist
npm run formatpasses and leaves this PR's files unchanged.biome ci .andnpm run typecheckinplayground/pass too.playground/web-document-editor.md, which the root README already links.README.mdwith description and quick start (if local example). Not applicable, this is a Playground snippet.