Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WWD2017 pdfkit to fill PDF form

In my swift application there is PDF form field which with all the fields name defined, I want to fill these fields programmatically, however watching the WWDC presentation, PDFKit first draw a frame around the field, meaning creating form field first than setting the vale as

textField.widgetStringVale = “WWDC 2017”

My questions are

1) is it possible to fill the PDF form with fields already created in adobe acrobat in swift programmatically instead of creating first using PDFKit

2) if not for 1) how to determine the absolute frame size for fields as there are many field so I don’t want to trial and error

enter image description here

like image 974
Codicil Avatar asked Oct 01 '17 07:10

Codicil


People also ask

Can you automate PDF form filling?

If you've ever had to edit PDF form and fill out fields by hand, it can soon turn into a real pain. A PDF file isn't plain text and requires specific software to read (and edit) them. One way to fill out PDF form fields in an automated script is to use the . NET Framework.

How can I fill a PDF form offline?

Save and download the PDF file. Click the green button Save & Download in the toolbar on the left side of the screen to save the PDF form to the device. "When you are filling out the file, click the blue button Save to save your operation in case of losing. "


1 Answers

Yes, you can use PDFKit to programmatically fill a PDF form:

import UIKit
import PDFKit

let pdfURL = ...
let document = PDFDocument(url: pdfURL!)
let page1 = document!.page(at: 0)

let field = page1?.annotations.filter({ $0.fieldName! == "ConferenceName" })
field?[0].widgetStringValue = "WWDC 2017"

let saveURL = ...
document!.write(to: saveURL)
like image 135
David Peckham Avatar answered Oct 16 '22 18:10

David Peckham