【问题标题】:WWD2017 pdfkit to fill PDF formWWD2017 pdfkit填写PDF表格
【发布时间】:2017-10-01 07:18:13
【问题描述】:

在我的 swift 应用程序中有一个 PDF 表单字段,其中定义了所有字段名称,我想以编程方式填充这些字段,但是观看 WWDC 演示文稿,PDFKit 首先在字段周围画一个框架,这意味着首先创建表单字段而不是将 vale 设置为

textField.widgetStringVale = “WWDC 2017”

我的问题是

1) 是否可以使用 adobe acrobat 中已创建的字段以编程方式快速填充 PDF 表单,而不是先使用 PDFKit 创建字段

2) 如果不是 1) 如何确定字段的绝对帧大小,因为字段很多,所以我不想反复试验

【问题讨论】:

    标签: ios swift ios11 pdfkit


    【解决方案1】:

    是的,您可以使用 PDFKit 以编程方式填写 PDF 表单:

    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)
    

    【讨论】:

    • 如何循环访问一个 fieldNames 数组来更新几个字段值?
    【解决方案2】:

    我只想添加一个用于测试目的的保存功能

    import UIKit
    import PDFKit
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    
     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"
    
     savePDF()
    }
    
     func savePDF() {
        #if targetEnvironment(simulator)
        let path = URL(string: "file:///Users/bbird/Desktop/PDFKit/awesome.pdf")!
        #else
        let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!.appendingPathComponent("awesome.pdf")
        #endif
        print(path)
        self.pdfView?.document?.write(to: path) //We don't really need to write this here - just demo'ing code
       }
    

    【讨论】:

      猜你喜欢
      • 2016-04-05
      • 2012-07-28
      • 2012-01-23
      • 1970-01-01
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      相关资源
      最近更新 更多