Skip to content

Embed the Template Editor

Use the embedded template editor when your users need to configure PDF templates without leaving your application.

Include the template editor JavaScript library:

Include template_editor.js
<script
type="text/javascript"
src="https://cdn.docspring.com/embed/template_editor.v0.1.1.js"
></script>

Render the editor inline:

Inline embedded editor
<div id="template-editor" style="height: 720px"></div>
<script>
DocSpring.createTemplateEditor('#template-editor', {
templateId: 'tpl_123',
token: 'EMBED_EDIT_TOKEN',
inline: true,
externalUser: {
name: 'Jane Editor',
external_id: 'user_123'
},
darkMode: false,
doneButtonLabel: 'Done',
onDone: function(data) {
// Close your modal or advance to the next step.
}
})
</script>

Or open it as a modal:

Modal embedded editor
DocSpring.createTemplateEditor({
templateId: 'tpl_123',
token: 'EMBED_EDIT_TOKEN'
})

Add your domain to the template’s Embed Domains setting so the editor can be loaded on your pages. Note: when Embed Domains is set but the embedding page sends no Referer or Origin header, the editor refuses to load. Leave the field blank only when you do not want any domain restriction. See Security for what the embed token can and cannot do.

The first argument can be a selector string (with options as the second argument) or a single options object. When a selector is provided the editor renders inline unless you pass inline: false; with no selector it opens as a modal.

OptionTypeRequiredDescription
templateIdstringYesTemplate ID, such as tpl_123.
tokenstringYesTemplate embed edit token.
externalUserobjectNoDetails for the user editing the template in your app. Used for “last changed by” and version publisher labels.
selectorstringNoTarget element for an inline editor. May be passed here instead of as the first argument.
inlinebooleanNoDefaults to true when a selector is provided. Pass false to force modal mode even with a selector.
darkModebooleanNoPass true to render the embedded editor with DocSpring’s dark theme, or false to force the light theme.
showDoneButtonbooleanNoShow a customizable done button in the editor header. Defaults to true.
doneButtonLabelstringNoLabel for the done button. Defaults to Done.
disableDoneButtonIfPredefinedFieldsMissingbooleanNoDisable the done button until every required_in_template predefined field has been added. Defaults to true.
featuresobjectNoPer-embed feature overrides.
closeModalOnClickOverlaybooleanNoIn modal mode, close the editor when the overlay behind it is clicked. Defaults to true.
fullScreenModalbooleanNoIn modal mode, remove the default side margins and use the full viewport width. Defaults to false.
modalMaxWidthstringNoIn modal mode, cap the iframe width with a CSS length such as 1200px or 80vw. Defaults to no max width.
iframeClassstringNoAdditional class names for the iframe.
iframeStylestringNoAdditional inline CSS for the iframe.
editorURLstringNoOverride the iframe URL. This is mainly useful for local development or custom routing.
regionstringNoUse a DocSpring region: US, EU, or AU. Defaults to US.
hoststringNoUse one host for both app and API URLs, usually for single-domain enterprise deployments.
appHoststringNoOverride the app host used for the editor iframe, usually for split-domain enterprise deployments.
apiHoststringNoOverride the API host for consistency with other embedded libraries.

Use region when your account is in the EU or AU region:

Regional embedded editor
DocSpring.createTemplateEditor('#template-editor', {
templateId: 'tpl_123',
token: 'EMBED_EDIT_TOKEN',
region: 'AU'
})

For single-domain enterprise deployments, use host:

Enterprise host
DocSpring.createTemplateEditor('#template-editor', {
templateId: 'tpl_123',
token: 'EMBED_EDIT_TOKEN',
host: 'https://docspring.example.com'
})

For split-domain deployments, use appHost and apiHost. Existing globals such as DocSpring.appHost, DocSpring.host, DocSpring.scheme, and DocSpring.port are still supported. If you pass editorURL, that full URL takes precedence and is also used to verify messages from the iframe.

externalUser supports these fields:

FieldTypeDescription
namestringDisplay name for editor attribution. Defaults to Embedded Template User.
emailstringEmail address for editor attribution metadata.
external_idstringYour application’s stable user ID.

If externalUser is omitted, embedded saves and published versions are attributed to Embedded Template User.

DocSpring.createTemplateEditor returns an object you can use to control the editor:

PropertyTypeDescription
iframeelementThe created <iframe> element.
closefunctionCloses the editor, removes its iframe and message listener, and fires onClose.
urlstringThe full editor URL loaded in the iframe.
Event callbacks
DocSpring.createTemplateEditor('#template-editor', {
templateId: 'tpl_123',
token: 'EMBED_EDIT_TOKEN',
inline: true,
onLoad: function(data) {},
onSave: function(data) {},
onVersionPublish: function(data) {},
onVersionRestore: function(data) {},
onVersionDelete: function(data) {},
onDocumentUpdate: function(data) {},
onDone: function(data) {},
onError: function(error) {},
onClose: function() {},
onEvent: function(eventName, data) {}
})

Each event has a named callback (onLoad, onSave, and so on). onEvent is a catch-all that fires for every event with the event name and its data. onClose fires when a modal editor is closed. Version events only fire when versioning is enabled for the embed.

The Done button only fires onDone when the editor has no pending changes, no active save request, and no save error. Host applications can use onSave to observe successful saves and onDone to advance or close the editor after the user clicks Done. If a save fails, the editor keeps Done disabled until the save error is resolved.

Template API responses include versions metadata for published template versions. Publisher IDs are split by actor type:

FieldDescription
published_by_typeuser for a DocSpring account user, or external_user for an embedded editor user.
published_by_user_idDocSpring user ID (usr_...) when published_by_type is user; omitted otherwise.
published_by_external_idYour externalUser.external_id when published_by_type is external_user; omitted when not provided.
published_by_nameDisplay name for the publisher.
published_by_emailExternal publisher email address when provided.

The embed edit token is a per-template edit credential, not a read-only key. Anyone holding it can edit the template through the embed API, and it is not a hidden secret: it appears in the editor URL and is returned in authenticated API responses. Treat it like an API key scoped to a single template and never expose a token for a template the end user should not be able to edit.

By default the token can only edit template content — fields, field layout, name, defaults, predefined fields, and HTML/SCSS. Three per-template capability flags (all default false) widen what an embed may do. They are enforced on the server, so they are the real boundary; the features options only control which controls are shown.

CapabilityDefaultAllows the embed to…
embed_edit_allow_settingsfalseEdit template settings such as the webhook URL, redirect URL, encryption password, public access, and expiration.
embed_edit_allow_versioningfalsePublish, restore, and delete versions, and view version history.
embed_edit_allow_document_replacementfalseUpload a replacement PDF document.

Set these with the authenticated API or in the dashboard. The matching features switches (showSettings, showVersions, allowPdfReplacement) are forced off when their capability is disabled, so a host cannot re-enable a disabled capability from the browser.

When embed_edit_allow_settings is false, the embedded editor also receives sanitized settings values in its boot payload and template JSON responses. Sensitive settings such as webhook URLs, Slack webhook URLs, redirect URLs, and PDF encryption passwords are returned as null or safe defaults. Enable embed_edit_allow_settings only when the embedded user should both view and edit those settings.

Regardless of any capability, the embed token cannot change the template’s Embed Domains, change the capability flags, lock the template, rotate its own token, copy the template, or delete the draft / entire template family. Those actions require account authentication (the dashboard or the authenticated API).

Embed Domains only restricts which origins may frame the editor (the iframe HTML load); it does not gate the JSON API, which is authenticated by the token. We recommend always setting Embed Domains in production.