2016-11-21 2 views
0

iText 7을 사용하여 PDF에 양식을 추가하려고합니다.iText7 setValue 메서드가 작동하지 않습니다

필드의 값을 설정하려고 할 때 계속 오류가 발생합니다. 나는 addKid() 방법의 documentation에서 정보를 찾을 수 없었다. 누구든지이 오류를 해결하는 방법을 알고 있습니까? 여기

내가 사용하고 코드의 샘플입니다 :이 PdfException 당신이 점점 오류를 추정

PdfTextFormField confField = PdfFormField.createText(pdf); 
confField.setFieldName(fieldName); 

PdfWidgetAnnotation confCoverAnnot = new PdfWidgetAnnotation(new Rectangle(x, y, width, height)); 
PdfWidgetAnnotation confAnnot = new PdfWidgetAnnotation(new Rectangle(x2, y2, width2, height2)); 

for (int i = 1; i<= numPages; i++) { 
    switch(i) { 
     case 1: 
      pdf.getPage(i).addAnnotation(confCoverAnnot); 
      break; 
     default: 
      pdf.getPage(i).addAnnotation(confAnnot); 
      break; 
    } 
} 


/* 
    Trying to have two different annotations reference the same field value. 

    Upon using the `setValue()` method, I get: object.must.be.indirect.to.work.with.this.wrapper 
    Any way to get this to work properly? 
*/ 
form.addField(confField); 
confField.addKid(confCoverAnnot); 
confField.addKid(confAnnot); 
if (value.equals("") != true) { 
    confField.setValue(value); //error here 
} 

답변

2

수 있습니다 : 스레드에서 예외가 "기본"com.itextpdf.kernel.PdfException : 개체가 있어야합니다 이 포장지로 간접적으로 작업 할 수 있습니까? '

용액들을 생성 한 후에게 간접적 같은 주석을 표시하는 것이다

PdfWidgetAnnotation confCoverAnnot = new PdfWidgetAnnotation(new Rectangle(x, y, width, height)); 
confCoverAnnot.makeIndirect(pdf); 
PdfWidgetAnnotation confAnnot = new PdfWidgetAnnotation(new Rectangle(x, y, width, height)); 
confAnnot.makeIndirect(pdf); 

설명 : iText7의 폼 필드의 값을 설정하면 , 그것은 주석 경유 오브젝트 것으로 예상하고 예외를 발생시킬 것이다 그렇지 않은 경우. PdfWidgetAnnotationPdfDocument과는 별도로 생성되므로 링크를 명시 적으로 지정해야합니다. makeIndirect()

+0

설명해 주셔서 감사합니다. 지금은 의미가 있습니다 :) – Elliot

관련 문제