Domanda

I use pdf.js library to generate html5 page from pdf but some capabilities not working. I try to get value for input radio but still abortively:( For example, in core.js script there are a few lines of code that take type of field:

var fieldType = getInheritableProperty(annotation, 'FT');
            if (!isName(fieldType))
              break;
            item.fieldType = fieldType.name;

How I can get feild value?

È stato utile?

Soluzione

I found the solution that work form me! Add this code around line 260 of core.js file:

function setRadioButton(annotation, item) {
    var ap = annotation.get('AP');
    var nVal = ap.get('N');
    var i = 0;
    nVal.forEach(function(key, value){
        i++;
        if(i == 1 || i == 2) {
            if(key != 'Off')
                item.value = key;
        }
    });
}

And this code around line 370 of core.js file:

if (item.fieldType == 'Btn') {
    if (item.flags & 32768) {                   
        setRadioButton(annotation, item);
    }
}

Also, if you want to get values from select input, you can use this code:

if(item.fieldType == 'Ch') {
    item.value = annotation.get('Opt') || []; //return array of values
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top