How to set value/text to textfield. Pdf doc is open using PTDocumentController

Product: PDFTron SDK

Product Version: 9.2.3 and 9.3.1

Please give a brief summary of your issue:
(Think of this as an email subject)

*we are able to set value or text to text filed of pdf using PTDocumentController & PTField *
but pdf page is not refreshing/Reflecting that value/Text.
On zooming in pdf that value/Text is refreshed.

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)

value/Text set to textfield but it reflect on zooming only. It need to show when pdf is open only.

below func we use to set n refresh value
field.setValueWith(“test”)

  • field.refreshAppearance()*

we open the document using PTDocumentController class
we use PTFieldIterator n PTField class
we checked on both ios sdk version 9.2.3 and 9.3.1

Please provide a link to a minimal sample where the issue is reproducible:

function to set the value to textfield.

let itr: PTFieldIterator = documentController.document!.getFieldIterator()

    while itr.hasNext()
    {

        let field: PTField = itr.current()
       
        if field.getType() == e_pttext {
            print("Text Field name: \(field.getName()!)")
            print("\(field.getValueAsString() ?? "")")
           // field.eraseAppearance()
            field.setValueWith("test")
            field.refreshAppearance()
        }
     
        itr.next()
      
    }

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi Nitesh,

setValueWith (_ value: String!) returns a viewChangeCollection. You can pass the returned value to PTPDFViewCtrl’s refreshAndUpdate(_ view_change: PTViewChangeCollection) method. This function that will refresh annotation and/or field appearances if needed, and then render modified page areas, all based on the contents of the view_change parameter.

Here’s how it would look like:

let itr: PTFieldIterator = documentController.document!.getFieldIterator()
        
        while itr.hasNext()
        {
            
            let field: PTField = itr.current()
            
            if field.getType() == e_pttext {
                print("Text Field name: \(field.getName()!)")
                print("\(field.getValueAsString() ?? "")")
                // field.eraseAppearance()
                if let viewChange = field.setValueWith("test") {
                    documentController.pdfViewCtrl.refreshAndUpdate(viewChange)
                }
                
            }
            
            itr.next()
            
        }

Let us know if this works for you.

Best Regards,
Sahil Behl.

Thanks for help!
Below code work for me.

documentController.pdfViewCtrl.update()
documentController.pdfViewCtrl.updatePageLayout()

Good to know you got it to working.

You can also get it to work by just calling documentController.pdfViewCtrl.update(), and don’t have to call updatePageLayout(). This function must be called
after document page sequence is modified (such as when a page is being added to or removed from a document) or after changes to page dimensions (e.g. after a page is rotated or resized).

Best Regards,
Sahil Behl.

1 Like