Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Fillable format extraction from pdf

Participant ,
Jun 30, 2025 Jun 30, 2025

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

TOPICS
JavaScript , PDF , PDF forms
321
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2025 Jun 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 01, 2025 Jul 01, 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';
    };
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2025 Jul 01, 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 02, 2025 Jul 02, 2025

Thanks Thom Parker, 

Since it was related to Javascript and PDF I have raised the query in this forum. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2025 Jul 02, 2025
LATEST

Different type of JavaScript. Context is important. 

 

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines