Copy link to clipboard
Copied
Hi All,
Good day to you!
I am trying to compare fillable form source and draft by extracting the details like filed name, tooltip, tab order, page number and char limit using browser based upload. However I am facing issued in extracting the formats of the fields, Below is the code which gives as "Text" for all field. Is it possible to extract information like SSN, Date...
Note: I use a script to fill the value of the field based on the format then I am doing the compare
const getFieldFormat = (annot) => {
const jsAction = annot.actions?.F || annot.additionalActions?.F || '';
if (typeof jsAction !== 'string') return 'Text';
if (/AFDate_Format/.test(jsAction)) return 'Date';
if (/AFNumber_Format/.test(jsAction)) return 'Number';
const match = jsAction.match(/AFSpecial_Format(\d)/);
if (match) {
switch (match[1]) {
case '0': return 'SSN';
case '1': return 'Phone Number';
case '2': return 'ZIP Code';
case '3': return 'ZIP+4';
default: return 'Special Format';
}
}
return jsAction ? 'Custom JS Format' : "Text";
};
Copy link to clipboard
Copied
You'll need to explain more. On what platform is this script being used? And using what SDK, library, or toolset?
Copy link to clipboard
Copied
Hi Thom Parker,
I am using browser based script which will run as HTML + JS. and i am extracting fillable information like filed name, tooltip, tab order, page number and char limit,. Below is the code sample for your reference.
<!-- PDF.js --> <script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@3.11.174/build/pdf.min.js"></script> <!-- SheetJS --> <script type="module" src="https://cdn.jsdelivr.net/npm/xlsx@0.18.5/+esm"></script> <script type="module"> import * as XLSX from 'https://cdn.jsdelivr.net/npm/xlsx@0.18.5/+esm'; const extractFields = async (arrayBuffer) => { const fields = []; const pdf = await pdfjsLib.getDocument({ data: arrayBuffer }).promise; for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) { const page = await pdf.getPage(pageNum); const annots = await page.getAnnotations(); annots.forEach((annot) => { if (annot.subtype === 'Widget' && annot.fieldType === 'Tx') { fields.push({ FieldName: annot.fieldName || '', Tooltip: annot.alternativeText || '', CharacterLimit: annot.maxLen || '', Format: getFieldFormat(annot), Page: pageNum }); } }); } return fields; }; const getFieldFormat = (annot) => { const jsAction = annot.actions?.F || annot.additionalActions?.F || ''; if (typeof jsAction !== 'string') return 'Text'; if (/AFDate_Format/.test(jsAction)) return 'Date'; if (/AFNumber_Format/.test(jsAction)) return 'Number'; const match = jsAction.match(/AFSpecial_Format(\d)/); if (match) { switch (match[1]) { case '0': return 'SSN'; case '1': return 'Phone Number'; case '2': return 'ZIP Code'; case '3': return 'ZIP+4'; default: return 'Special Format'; } } return jsAction ? 'Custom JS Format' : 'Text'; };
Copy link to clipboard
Copied
So, did you check the browser console window to see if any errors were reported?
The function is probably returning "Text" because "jsAction" is not a string. Perhaps you should do some debug to figure out what type of animal it is? Probably an object with some sub-parts that contain the actual JS code.
However, this is all irrelevant because this forum is for questions about Adobe Acrobat.
You'll need to ask about this on another forum, one that is for browser scripting.
Copy link to clipboard
Copied
Thanks Thom Parker,
Since it was related to Javascript and PDF I have raised the query in this forum.
Copy link to clipboard
Copied
Different type of JavaScript. Context is important.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now