2011-04-27 4 views
1

단추 필드가있는 편집 가능한 pdf가 있습니다. iTextsharp를 사용하여 내 vb.net 응용 프로그램에서이 편집 가능한 pdf를 처리 중입니다. 어떻게 잡아서 PDF 내의 버튼 필드의 Click 이벤트를 처리하는지 알고 싶습니다. ** Sample Document can be found here 비록 iTextSharp dll을 사용하고 있는데 버튼 이벤트를 처리하는 데 도움이되는 리소스를 찾을 수 없습니다. vb.net을 사용하여 프로그래밍 방식으로 이러한 pdf를 처리하는 방법을 안내하십시오.iTextSharp + vb.net에서 양식 단추 클릭 이벤트를 처리하는 방법

답변

1

필드의 "마우스 업"추가 조치 사전에 PdfAction을 첨부해야합니다.

기존 필드에 작업을 추가하는 것은 처음부터 그렇게하는 것이 더 어렵지만 여전히 가능합니다.

(Appologies하지만, 당신은 자바에서 번역해야합니다 모든 vb.net을 모르는) 특정 경우

// 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 니스, 나는 이것이 가능하다고 생각하지 않았다. –

관련 문제