2017-09-27 6 views
2

enter image description here 내 응용 프로그램에는 사용자 입력을 기반으로하는 PDF 양식이 있습니다. 필자는 PDF 형식으로 값을 강제 적용합니다. 내 응용 프로그램 (신속한 3,하지만 PDFKit 주위에 있기 때문에 iOS 11 에서이 일을 위해 ILPDFKit 꼬투리를 사용하고 있었는데, 이것이 PDFKit을 사용하여 가능한지 알고 싶습니다). 내가 ILPDFKit에 사용 된 코드는했다 :iOS를 사용하여 프로그래밍 방식으로 PDF 양식 필드 채우기 PDFKit

// set the pdf form as ILPDFDocument 
let document = ILPDFDocument(resource:"ExamplePDFfrom") 

// Manually set a form value for field name (created in adobe acrobat) 
document.forms.setValue("David", forFormWithName: "FirstName") 

답변

2

업데이트 대답

@objc func pdfPageChanged() { 
    for index in 0..<doc!.pageCount{ 
     if let page = doc?.page(at: index){ 
      let annotations = page.annotations 
      for annotation in annotations{ 
       print("Annotation Name :: \(annotation.fieldName ?? "")") 
       if annotation.fieldName == "firstName"{ 
        annotation.setValue("David", forAnnotationKey: .widgetValue) 
        page.removeAnnotation(annotation) 
        page.addAnnotation(annotation) 
       }else if annotation.fieldName == "checkBox"{ 
        annotation.buttonWidgetState = .onState 
        page.removeAnnotation(annotation) 
        page.addAnnotation(annotation) 
       } 
      } 
     } 
    } 
} 

문서가

+0

장하다 Saurabh이 정확하게 일을 할 PDFDocument의 개체 덕분에 많은 – Codicil

+0

당신입니다 오신 것을 환영합니다! –

+0

라디오 버튼과 체크 박스 값을 yes로 설정하는 방법은 하나의 질문이지만,이 방법은 첫 번째 페이지에서만 작동합니다. 두 번째 페이지의 주석에 대해서는 두 번째 페이지의 – Codicil