In iOS, how can you programmatically fill out a pdf form field? In iOS, how can you programmatically fill out a pdf form field? objective-c objective-c

In iOS, how can you programmatically fill out a pdf form field?


I doubt that kind of functionality will ever be in the iOS frameworks. The reason most of the related info you can find "seem[s] geared towards displaying or creating pdf content instead of modifying it" is because that's what the vast majority of use cases will want or need for PDF functionality.

You'll need to find a 3rd party library that can open up PDFs, fill out the AcroForm fields, and then stamp out a PDF. I use iText on Java (there is also iTextSharp for C#) but I don't know of anything for Objective-C.

Once you find that library, you'll need to integrate it into your project. There are undoubtedly several related questions/answers here on SO for whatever version of the SDK you're using.


This would be easier to do with a HTML page. If you wish to use a HTML page instead of a .pdf form then thius is how you would go about doing it:

[field1 setText:@"Field 1 Text"];[field2 setText:@"Field 2 Text"];NSString *result;result = [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"$('#field1').val('%@');", field1.text]];result = [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"$('#pfield2').val('%@');", field2.text]];result = [webView stringByEvaluatingJavaScriptFromString:@"$('#submitbutton').click();"];

You would need to create two UILabels or UITextFields and call them "field2" and "field2" in your .h file. You can then find the ID of the field you need to replace e.g. #field1 and then put it where I have put "#field1" and again for the second field where I have put "#field2". There also needs to be a UIWebView with the page already loaded. This code is to be used after the UIWebView page has been loaded. Maybe do the following:

-(void)webViewDidFinishLoad:(UIWebView *)webView {// Insert above code here}

You probably need a full understanding of Javascript if you want to do this for the whole form, but this should get you started.

Hope that helps you.