【问题标题】:iTextSharp + How to handle the form button field click event in vb.netiTextSharp + 如何处理 vb.net 中的表单按钮字段单击事件
【发布时间】:2011-04-27 15:39:21
【问题描述】:

我有一个可编辑的 pdf,其中包含按钮字段。我正在使用 iTextsharp 在我的 vb.net 应用程序中处理这个可编辑的 pdf。想知道如何捕捉和处理pdf中按钮字段的Click事件。 **Sample Document can be found here 虽然,我使用的是 iTextSharp dll,但我找不到任何有用的资源来处理按钮事件。 请指导如何使用 vb.net 以编程方式处理此类 pdf。

【问题讨论】:

    标签: pdf button field itextsharp


    【解决方案1】:

    您需要将PdfAction 附加到该字段的“鼠标向上”附加操作字典。

    向现有字段添加操作比从头开始要困难一些,但仍然很有可能。

    (请教,但我根本不懂vb.net,你得从Java翻译过来)

    // Create your action.
    // There are quite a few static functions in PdfAction to choose from.
    PdfAction buttonAction = PdfAction.javaScript(writer, scriptStr);
    
    AcroFields.Item buttonItem = myAcroFields.getFieldItem(buttonFldName);
    
    // "AA" stands for "additional actions"
    PdfDictionary aaDict = buttomItem.getMerged(0).getAsDict(PdfName.AA);
    if (aaDict == null) {
      aaDict = new PdfDictionary();
    } else { // this button already has an AA dictionary.
      // if there's an existing up action, preserve it, but run ours first.
      PdfDictionary upAction = aaDict.getAsDict(PdfName.U);
      if (upAction != null) {
        PdfIndirectReference ref = aaDict.getAsIndirect(PdfName.U);
        if (ref != null) {
          buttonAction.put(PdfName.NEXT, ref);
        } else {
          buttonAction.put(PdfName.NEXT, upAction);
        }
      }
    }
    
    aaDict.put(PdfName.U, buttonAction);
    
    int writeFlags = AcroFields.Item.WRITE_WIDGET | AcroFields.Item.WRITE_MERGED;
    buttomItem.writeToAll(PdfName.AA, aaDict, writeFlags);
    

    在您的特定情况下,您可以简单地:

    PdfDictionary aaDict = new PdfDictionary();
    aaDict.put(PdfName.U, buttonAction);
    item.getWidget(0).put(PdfName.AA, aaDict);
    

    这将清除所有现有操作。这对你来说可能没问题,但可能非常糟糕。

    【讨论】:

      猜你喜欢
      • 2011-10-16
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多