Signers and groups
A contract has the buyer’s part and the seller’s part. The buyer fills in and signs the buyer’s fields, the seller the seller’s, and once the buyer has signed, nobody changes what the buyer filled in. Groups do this: each field belongs to a group, and each user’s permissions say which groups they fill in and sign.
const { fields } = await doc.forms.list();
fields.map((field) => [field.name, field.groupId]);
// [['buyer.name', 'buyer'], ['buyer.signature', 'buyer'], ['seller.name', 'seller'], …]Put fields in groups#
A field’s group is its groupId, the shorthand for its assignment.
Give it when you create the field, or change it later:
await doc.forms.create({
kind: 'text',
name: 'buyer.name',
groupId: 'buyer',
widgets: [{ page, rect: { x: 72, y: 120, width: 200, height: 24 } }],
});
await doc.forms.update(field.ref, { groupId: 'seller' });A field you create without a groupId is in no group, whatever your own group is
(identity.groupId): a field is somebody’s once you say whose. groupId: null in the draft
means the same as leaving it out: the field is unassigned.
Putting a field in your own group takes no permission of its own. Putting it in another group
takes fields:set-group for that group, so a designer who prepares the contract gets one for
each party:
const designer = [
'doc.open',
'doc.render',
'doc.forms.modify',
'fields:set-group:group=buyer',
'fields:set-group:group=seller',
];null takes a field out of its group:
await doc.forms.update(field.ref, { groupId: null });That takes doc.forms.modify and no fields:set-group permission: whoever designs the form may
take a field out of any group, as they may delete it. An unassigned field can only be filled in
by a user who may fill in every field.
The group is a setting of the field: it’s saved in the PDF (in the field’s /EMBD_Metadata),
other PDF apps ignore it, and a form export carries it.
Who fills a field in#
A field’s assignment says who fills it in, one of three:
assignment | Who fills it in |
|---|---|
{ kind: 'group', groupId: 'buyer' } | The users who may fill in that group’s fields |
{ kind: 'anyone' } | Every user who may fill in some field: each signer, and the sender |
{ kind: 'unassigned' } | The users who may fill in every field: the sender |
groupId reads the group’s id for the first, and null for the other two.
Some fields belong to no one signer: a reference number whoever signs first knows, a delivery date either party may settle. Give such a field to anyone:
const { field } = await doc.forms.create({
kind: 'text',
name: 'delivery.date',
assignment: { kind: 'anyone' },
widgets: [{ page, rect: { x: 72, y: 200, width: 120, height: 24 } }],
});
field.assignment; // { kind: 'anyone' }
field.groupId; // nullAn assignment works whatever the field’s assignment was, and so does groupId: a group id
makes the field that group’s, and null an unassigned one.
await doc.forms.update(field.ref, { assignment: { kind: 'group', groupId: 'buyer' } });
await doc.forms.update(field.ref, { assignment: { kind: 'anyone' } });
await doc.forms.update(field.ref, { groupId: null }); // unassignedA write names one of the two: assignment and groupId together fail with InvalidArg, and so
does { kind: 'anyone' } on a signature field, which one signer signs.
A field anyone fills in lets every group’s signers fill it in, so giving it to anyone takes the
permission to put fields in every group, fields:set-group:all, beside doc.forms.modify. A
group takes fields:set-group for that group, as above, and unassigned takes
doc.forms.modify alone. The assignment a field already has takes none.
Like the group, the assignment is saved in the field’s /EMBD_Metadata, other PDF apps ignore it,
and a form export carries it. Signing locks a field anyone fills in once it holds a
value.
Give each signer their group#
Each signer gets the permissions to fill in and sign their own group’s fields:
const buyer = ['doc.open', 'doc.render', 'fields:fill:group=buyer', 'fields:sign:group=buyer'];
const seller = ['doc.open', 'doc.render', 'fields:*:group=seller'];const doc = await engine.open(
{ kind: 'bytes', bytes },
{ scope: buyer, identity: { userId: 'u_381', displayName: 'Dana Smith' } },
);Every user who may read the form sees every field and every value: groups decide who changes a field, not who sees it. When one signer must not see another’s answers, give each their own document.
Leave doc.forms.modify and pdf.permissions out of a signer’s permissions. Designing the form
can delete and recreate any field, and pdf.permissions gives what the PDF file allows to
everyone, which can include designing it.
Filling in#
A signer fills in their fields as anyone does. A field of another group fails with Forbidden,
naming the permission it would take:
await doc.forms.setValue(buyerName.ref, { value: 'Dana Smith' });
await doc.forms.setValue(sellerName.ref, { value: 'x' });
// Forbidden: details.required is 'fields:fill:group=seller'
await doc.forms.setValue(deliveryDate.ref, { value: '2026-12-01' }); // anyone's field: allowedA field a script calculates, such as a total, may be in another group or in none. Write it in the same change as the field it’s calculated from, and it’s allowed:
await doc.apply({
ops: [
{ type: 'forms.setValue', field: price.ref, value: { value: '1200' } },
{ type: 'forms.setValue', field: total.ref, value: { value: '1452' } },
],
});A reset that names a field the signer may not fill in is refused, and so is a reset of the whole
form, so pass their own: doc.forms.reset(myFields). A values import
leaves out the other fields, with the reason fill-not-allowed.
Signing#
A signer signs their own signature field, and only theirs:
const prepared = await doc.signatures.prepare({ field: buyerSignature.ref });When you name no lock, signing locks what the signer has seen:
- The rest of the group, when the signature field is in one: every field in it as it is when the buyer signs, except its signature fields.
- Every field anyone fills in that holds a value, whoever filled it in: this signer, an earlier one, or the sender before sending. This holds for a signature field in no group too.
After that, writing one of them fails with ProtectedDocument for everyone, in this engine and in
other PDF apps. A field anyone fills in still empty when the buyer signs stays open: the seller may fill
it in, and it locks when the seller signs. Name a
lock to choose the fields yourself; then nothing is
added to it. Nothing is added either when the PDF already locks the signature field itself (its own
/Lock, which another tool may have set): the signing locks what that lock says.
The engine doesn’t order the signers. Give the seller their permissions when the buyer is done.
Validation data, and the document timestamp that follows it, belong to the document and not to a
group, so they take doc.sign. A signer who should leave a file that can be checked for years gets
it beside their group:
const buyer = [
'doc.open',
'doc.render',
'doc.sign',
'fields:fill:group=buyer',
'fields:sign:group=buyer',
];It lets them sign nothing more. While the list has a fields:sign permission, that alone decides
which fields they sign: not the seller’s, and not a field in no group.
Build the interface from it#
Ask before you show a control:
doc.security.allowsField('fill', field); // may the user fill this field in?
doc.security.allowsField('sign', field); // …sign this signature field?
doc.security.allowsField('set-group', { groupId: 'buyer' }); // …put fields in the buyer's group?To show whose fields are the user’s before they pick one, ask for every field at once:
const rights = doc.security.fieldRights();
rights.fill; // { all: true }, or { all: false, groups: ['buyer'] }
rights.sign; // the same, for signature fields
rights.setGroup; // the groups the user may put a field in{ all: true } is every field. Otherwise only the fields in groups are the user’s; an
unassigned field isn’t, and an empty list is no field at all. A field anyone fills in is the
user’s to fill in unless fill is that empty list. A user may give fields to anyone when
setGroup is { all: true }.
The engine checks every write the same way, so these answers never disagree with a call. See Permissions.
Your feedback goes directly to the documentation team.