Skip to main content

Embedding forms into a web page

ONLYOFFICE Docs supports PDF forms — PDF files with fillable fields such as text inputs, checkboxes, and dropdowns. A PDF form has two usage modes:

note

PDF forms are available starting from version 7.0. Starting from version 8.0, the OFORM format is deprecated — only PDF is used for filling. Starting from version 8.1, the DOCXF format is deprecated — only PDF is used for creating and editing forms.

warning

When JWT validation is enabled on your document server (the default configuration), each config must be signed with a matching token. Sign with your document server's JWT secret. See the Signature section for setup instructions and code examples.

In the HTML examples below, replace documentserver with the address of the server where ONLYOFFICE Docs is installed.

Editing forms​

To open a PDF form for editing, set documentType to "pdf" and permissions.edit to true. Provide a key so that multiple users can co-edit the form template simultaneously:

const config = {
document: {
fileType: "pdf",
key: "form-template-key",
permissions: {
edit: true,
},
title: "Form Template.pdf",
url: "https://example.com/url-to-example-form.pdf",
},
documentType: "pdf",
};

const docEditor = new DocsAPI.DocEditor("placeholder", config);

The complete HTML page:

<script type="text/javascript" src="https://documentserver/web-apps/apps/api/documents/api.js"></script>
<button onclick="openFormTemplate()">Open Form Template</button>
<div id="placeholder"></div>
<script>
let docEditor;

function openFormTemplate() {
if (docEditor) {
docEditor.destroyEditor();
}

const config = {
"document": {
"fileType": "pdf",
"key": "form-template-key",
"permissions": {
"edit": true
},
"title": "Form Template.pdf",
"url": "https://example.com/url-to-example-form.pdf"
},
"documentType": "pdf",
"events": {
"onRequestStartFilling": function () {
docEditor.startFilling();
},
"onStartFilling": function () {
console.log("The form is ready for filling");
}
}
};

docEditor = new DocsAPI.DocEditor("placeholder", config);
}
</script>

The Share & collect button appears only if the onStartFilling or onRequestStartFilling event is declared. With onStartFilling alone, the button opens the built-in Send for signing panel, which gets its list of users from the onRequestUsers event. To handle the click with your own code instead, declare onRequestStartFilling and call the startFilling method from its handler. That method works only if onStartFilling is also declared.

In this example, click Share & collect after editing. The editor calls the page's onRequestStartFilling handler, which calls startFilling. The editor then locks the form against further editing, saves it, and calls onStartFilling when the save completes.

Embed pdf form for editingEmbed pdf form for editing

Filling forms​

To open a PDF form for filling, set permissions.edit to false and permissions.fillForms to true. Omit the key parameter — the editor will generate a random key for each session, so every user fills out an independent copy without affecting others:

const config = {
document: {
fileType: "pdf",
permissions: {
edit: false,
fillForms: true,
},
title: "Form.pdf",
url: "https://example.com/url-to-example-form.pdf",
},
documentType: "pdf",
};

const docEditor = new DocsAPI.DocEditor("placeholder", config);

The complete HTML page:

<script type="text/javascript" src="https://documentserver/web-apps/apps/api/documents/api.js"></script>
<button onclick="openForm()">Open Form</button>
<div id="placeholder"></div>
<script>
let docEditor;

function openForm() {
if (docEditor) {
docEditor.destroyEditor();
}

const config = {
"document": {
"fileType": "pdf",
"permissions": {
"edit": false,
"fillForms": true
},
"title": "Form.pdf",
"url": "https://example.com/url-to-example-form.pdf"
},
"documentType": "pdf"
};

docEditor = new DocsAPI.DocEditor("placeholder", config);
}
</script>

After filling in all required fields, click Complete & Submit to submit the data.

Embed pdf formEmbed pdf form