Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/build-pdf-browser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@simplepdf/embed': minor
'@simplepdf/react-embed-pdf': minor
---

**Build and revise PDFs directly in the browser editor.**
- Use typed JavaScript and React methods for PDF building and task documentation.
- View the first-page preview with the build result and inspect other open-document pages by page number. WebMCP returns each preview as a native image.
12 changes: 9 additions & 3 deletions embed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ createEmbed({ target: '#editor', companyIdentifier: 'acme', document: { url: 'ht
```

- **Off by default.** `{ enabled: false }` and omitting the option are the same state.
- **The tools are the editor's own.** Each one is the record the editor publishes in its manifest (`https://simplepdf.com/embed/json`, `operations[].tool`) and registers on its own page: the `simplepdf_embed_*` name, description, snake_case input schema and behavior hints (the readers carry the specification's `readOnlyHint` and `untrustedContentHint`; every other tool MCP's `destructiveHint`; the three that fetch an agent-supplied URL `openWorldHint`). A page gets the same tools whether the editor is embedded or opened directly. `exclude` takes SDK method names.
- **The tools are the editor's own.** Each one is the record the editor publishes in its manifest (`https://simplepdf.com/embed/json`, `operations[].tool`) and registers on its own page: the published tool name, description, snake_case input schema and behavior hints (the readers carry the specification's `readOnlyHint` and `untrustedContentHint`; every other tool MCP's `destructiveHint`; those that fetch an agent-supplied URL or requested Google Fonts `openWorldHint`). `build_pdf` and `get_documentation` use those names; existing tools retain the `simplepdf_embed_` prefix. A page gets the same tools whether the editor is embedded or opened directly. `exclude` takes SDK method names.
- **Data path.** Every operation an agent can call runs in the browser, and nothing the agent reads (field values, extracted text, a page render) is computed server-side; it goes to the agent runtime the person attached, so treat that runtime as you would any other party that sees the filled document. Document storage is unchanged by this option: it follows your account's configuration exactly as it does without WebMCP (SimplePDF-managed storage, or your own S3, Azure Blob Storage or SharePoint), and `submit` sends the document through the same submission flow as a click on Submit.
- **Timing.** Tools register once the editor is ready. While no usable model context has been found, the page is probed again on each later lifecycle transition, so a context installed after `EDITOR_READY` is still picked up, and until one appears nothing is loaded (`webmcp.unavailable` is logged, with the reason).
- **Results.** The editor validates each call like any other request (its permission model applies at call time: editing, allowlisted origin, plan, so a tool your configuration refuses resolves with the matching error code). A call resolves with an MCP tool result whose text is the editor's wire-shaped `{ success, data | error }` Result (`isError` on failure); `simplepdf_embed_get_annotated_page` carries its PNG as an `image` content block, with the badges map in the text block. A call the runtime aborted before it ran rejects and never reaches the editor.
- **Results.** The editor validates each call like any other request (its permission model applies at call time: editing, allowlisted origin, plan, so a tool your configuration refuses resolves with the matching error code). A call resolves with an MCP tool result whose text is the editor's wire-shaped `{ success, data | error }` Result (`isError` on failure). A successful page render from `build_pdf` or `simplepdf_embed_get_annotated_page` carries its PNG as an `image` content block and its field badges in the text block. A call the runtime aborted before it ran rejects and never reaches the editor.
- **One embed per page.** A model context is one per page and keyed by tool name: a second WebMCP-enabled embed registers only the names the first did not take, and is reported for the rest (`webmcp.tool_already_registered`). `dispose()` unregisters everything.

## Subpaths
Expand Down Expand Up @@ -170,6 +170,8 @@ else r.error.code // a closed BridgeErrorCode
`embed.actions.*`: method names + arguments are camelCase (the snake_case wire is generated + transformed for you; [`/embed/json`](https://simplepdf.com/embed/json) or `@simplepdf/embed/schemas` carry every field):

```ts
await embed.actions.getDocumentation({ topic: 'build_pdf' })
await embed.actions.buildPdf({ action: 'build', code: '= Hello' })
await embed.actions.loadDocument({ dataUrl, name, page })
await embed.actions.goTo({ page: 3 })
await embed.actions.selectTool({ tool: 'TEXT' }) // 'CHECKBOX' | 'SIGNATURE' | 'PICTURE' | 'COMB_TEXT' | null
Expand All @@ -184,7 +186,11 @@ await embed.actions.rotatePage({ page: 1 })
await embed.actions.download()
```

Full set: `batchSetFieldValues`, `createField`, `deleteFields`, `deletePages`, `detectFields`, `download`, `focusField`, `getAnnotatedPage`, `getDocumentContent`, `getFields`, `goTo`, `loadDocument`, `movePage`, `rotatePage`, `selectTool`, `setFieldValue`, `submit`.
Full set: `buildPdf`, `getDocumentation`, `batchSetFieldValues`, `createField`, `deleteFields`, `deletePages`, `detectFields`, `download`, `focusField`, `getAnnotatedPage`, `getDocumentContent`, `getFields`, `goTo`, `loadDocument`, `movePage`, `rotatePage`, `selectTool`, `setFieldValue`, `submit`.

Start a build in an empty editor. If the job is still `running` after five seconds, call `buildPdf({ action: 'status', jobId })` until it finishes. A failed build reports diagnostics in `error`. A successful build opens the PDF and returns its page count, warnings and a first-page `preview`. Check `preview.success` before reading `preview.data.imageDataUrl`. To inspect another page of the currently open document, call `getAnnotatedPage({ page: 2 })`. Build preview identity is checked internally; page inspection has no build-specific parameters. Manual edits protect the document from replacement by a subsequent build.

Call `getDocumentation()` for the topic index, then `getDocumentation({ topic })` to read a topic.

**"Fill and read this document for me"** is just these operations in sequence, exactly what the agentic tools expose to a model:

Expand Down
Loading
Loading