Skip to content

commands.mupdf

The MuPDF facade reads and annotates the open PDF document.

const api = window.Amnesia; // or this.app.plugins.plugins['amnesia']?.api
const text = await api.commands.mupdf.extractPageText(1);
Method Purpose Capability
extractPageText(page) Extract text from a page; resolves to a text-extraction result. read-document
extractRegion(region) Extract text/content for a region of the page. read-document
snapSelection(selection) Snap a raw selection to document geometry. read-document
copySelection(selection) Produce a copyable representation of a selection. read-document
highlightSelection(selection) Create a highlight from a selection. write-annotations
createAnnotation(annotation) Create a PDF annotation; resolves to the created PDFAnnotation. write-annotations
getAnnotations(page) List annotations on a page. read-document
deleteAnnotation(id) Delete an annotation by id. write-annotations
getPageCount() Resolve the document’s page count. read-document
getPageDimensions(page) Resolve a page’s dimensions. read-document
search(query) Search the document; resolves to matches. read-document

Method names are exact. Geometry and annotation payloads use the MuPDF types (PDFPoint, PDFBounds, TextExtractionResult, PDFAnnotation, PDFSelectionMode) from the API type definitions.

  • Async-only. Every method returns a Promise; the async boundary lets the engine throttle or offload rendering work.
  • Capability-gated. Read primitives require read-document; annotation writes require write-annotations. A gated call on an under-scoped connect() handle throws PermissionError. The PermissionError at the facade is shipped and proven; the connect() capability-scoping that makes a handle under-scoped is itself experimental and untested.
  • No raw bridge. The shared rendering bridge is never returned. Build on these methods only.
  • Platform. The rendering path depends on native components; probe availability and degrade gracefully rather than assuming it on mobile.

Reference verified as of 2026-06-28.