Skip to main content
Known Participant
June 30, 2025
Question

Fillable format extraction from pdf

  • June 30, 2025
  • 1 reply
  • 429 views

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";
};

1 reply

Thom Parker
Community Expert
Community Expert
June 30, 2025

You'll need to explain more. On what platform is this script being used? And using what SDK, library, or toolset?

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
July 1, 2025

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';
    };
Thom Parker
Community Expert
Community Expert
July 1, 2025

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. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often