Skip to main content

Checking PDF forms

PDF forms differ from standard PDF files in form metadata. This metadata determines which editor opens a file: the form editor or the standard PDF editor.

To distinguish standard PDF files from PDF forms, you can use the check functions. These functions take the first 300 bytes of the file and check if there is "ONLYOFFICEFORM" there. If true, then it is a PDF form. Otherwise, it is a standard PDF file.

note

You can speed up file opening by specifying the document.isForm parameter.

The following examples show check functions in different programming languages.

function isExtendedPDFFile(text) {
if (!text) {
return false;
}
const indexFirst = text.indexOf("%\u00CD\u00CA\u00D2\u00A9\u000D");
if (indexFirst === -1) {
return false;
}
let pFirst = text.slice(indexFirst + 6);
if (!(pFirst.lastIndexOf("1 0 obj\u000A<<\u000A", 0) === 0)) {
return false;
}
pFirst = pFirst.slice(11);
const signature = "ONLYOFFICEFORM";
const indexStream = pFirst.indexOf("stream\u000D\u000A");
const indexMeta = pFirst.indexOf(signature);
if (indexStream === -1 || indexMeta === -1 || indexStream < indexMeta) {
return false;
}
let pMeta = pFirst.slice(indexMeta);
pMeta = pMeta.slice(signature.length + 3);
let indexMetaLast = pMeta.indexOf(" ");
if (indexMetaLast === -1) {
return false;
}
pMeta = pMeta.slice(indexMetaLast + 1);
indexMetaLast = pMeta.indexOf(" ");
if (indexMetaLast === -1) {
return false;
}
return true;
}