Getting export value from a choice field in a PDF -
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about iOS development and PDF
  • Page:
  • 1

TOPIC: Getting export value from a choice field in a PDF

Getting export value from a choice field in a PDF 1 week 5 days ago #14469

  • fuelware
  • fuelware's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Thank you received: 0

File Attachment:

File Name: StuntRiskAssessment.pdf
File Size: 174 KB

The attached form contains a number of drop-downs that are used in calculations. The user is able to choose frequency and impact which are mapped to a number using the export value of the dropdown.
The library doesn't seem to directly provide both values from an entry in the Opt array where the entry is a two-item array instead of just a text string so I'm using the code below to get the export value instead of the label (where it exists); annot is the PDFAnnot object and inDoc the PDFDoc object that holds it:

        if annot.getComboSel() < annot.getComboItemCount() {
                //see if there are export values; if so use them
                let obj = inDoc.advanceGetObj(annot.advanceGetRef())
                let optArray = obj?.dictGetItem(byTag: "Opt")
                    let optCount = optArray?.arrayGetItemCount(),
                    optCount > annot.getComboSel(),
                    let selectedItem = optArray?.arrayGetItem(annot.getComboSel() ),
                    selectedItem.getType() == 6 //array
                    if let exportValue = selectedItem.arrayGetItem(0)?.getNameVal() {
                        return exportValue as AnyObject
                if let txt = annot.getComboItem(annot.getComboSel()) {
                    return txt as AnyObject
                } else {
                    return "" as AnyObject
This gets the export value for these fields in the attached PDF:
impact_row5.0 through impact_row5.5
frequency_row5.0 through frequency_row5.5
frequency_row1.0 through frequency_row1.3

However when used on fields post_freq_1, post_impact_1, post_freq_2.0 through post_freq_2.8 and post_imp_2.0 through post_imp_2.8 the value for optArray is a zero-length array (when it should be a 6 item array). The Opt array for those controls is an indirect reference; when I manually request the object using its reference number and inDoc.advanceGetObj() (226 0 and 229 0 for the post_freq_2.x and post_imp_2.x respectively) I get the appropriate array. However optArray has a type of 6 (=> array?) and no indirect reference. Am I trying to retrieve this incorrectly and is there a better way to do it? Thanks.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum