2011-04-27 60 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