Built-in actions: View, Print and Submit

Add View, Print and Submit to the designer toolbar with a few lines. Code examples in the DocStudio developer reference.

The designer can show View, Print and Submit buttons on the right side of its toolbar. They work in the browser only. They need no server, no API endpoint, no Playwright and no Chromium.

The action group is optional. Nothing is added to the toolbar until you pass actions, onSubmit, onView or onPrint.

The smallest setup

With only onSubmit, the toolbar shows View, Print and Submit.

What each action does

Action Default behavior Override
View Opens a modal with the rendered document only: no designer controls. It shows the latest template and data. Render errors are listed in the modal. Esc closes onView(payload)
Print Renders the print target and opens the browser print dialog for the document only, in a hidden frame that is removed afterwards. Multi-page output is supported onPrint(payload)
Submit Calls onSubmit(payload). When it returns or its promise resolves, the designer shows Saved. If it throws or rejects, the template stays unsaved none, it is your own action

When you pass onView or onPrint, your function replaces the default. Print is never sent to a server.

The payload

Every callback receives exactly this object:

{
  (template, data);
}

template is the current template JSON and data is the current sample data. The payload has no HTML, compiled tree, diagnostics or editor state. Call renderDocument yourself if you need output.

Configure the actions

actions turns each button on or off and changes its label:

actions={{ view: true, print: false, submit: { label: 'Save report' } }}
  • view and print are on unless you set them to false.
  • submit appears only when onSubmit is provided. Set it to false to hide it.
  • Labels default to the strings in messages.actions.

Without React

Use the same pipeline in any browser code:

renderDocument(template, data, options) compiles and renders in one call and returns { ok, html, diagnostics }. printHtml(html) is in docstudio/pdf and resolves when the print dialog closes.

Limits

  • While authoring a component (mode: 'component'), only Submit is offered, because the document is not a complete template.
  • Browser printing depends on the browser's print engine. For server-rendered PDF files use docstudio/server, which is not part of the action group.
  • Submit is not disabled for a template with problems. Check the Problems tab, or validate in your handler.