2011-04-27 76 views

回答

1

您需要将PdfAction附加到该字段的“鼠标移动”附加动作字典。

要添加一个动作到现有的字段比从头开始难,但仍然很有可能。

(Appologies,但我不知道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); 

这将消除任何现有的操作。这可能对你很好,它可能是非常糟糕的。

+0

+1不错,我不认为这是可能的。 – 2011-04-27 21:06:42