【问题标题】:Pdf.js: how to get input radio values?Pdf.js:如何获取输入单选值?
【发布时间】:2013-07-14 09:42:55
【问题描述】:

我使用 pdf.js 库从 pdf 生成 html5 页面,但某些功能不起作用。我试图获得输入收音机的价值,但仍然失败:( 例如,在 core.js 脚本中,有几行代码采用字段类型:

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

如何获得字段值?

【问题讨论】:

    标签: javascript html pdf input pdf.js


    【解决方案1】:

    我找到了适合我的解决方案! 在 core.js 文件的第 260 行添加此代码:

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

    这段代码在 core.js 文件的第 370 行:

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

    另外,如果你想从选择输入中获取值,你可以使用这个代码:

    if(item.fieldType == 'Ch') {
        item.value = annotation.get('Opt') || []; //return array of values
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2020-06-01
      • 1970-01-01
      • 2017-09-09
      • 1970-01-01
      • 2013-04-06
      相关资源
      最近更新 更多