有没有办法检查 PDFKIT 中 Pdf 表单的所有字段是否已填写?

发布于 2025-01-09 20:43:52 字数 964 浏览 1 评论 0原文

有什么办法可以找到当前pdf内容的大小。

例如:-

当用户打开 pdf 文件并在 pdf 中填写一些信息并单击提交按钮时。那么如何检查pdf内容大小意味着内容是否完全填充。如果用户未完全添加详细信息,等待 pdf 中的某些 TextFiled,那么我们需要显示警报“请填写所有信息”。

   override func viewDidLoad() {
    super.viewDidLoad()
    
    setupNavigationBar()
    
    self.view.addSubview(pdfView)
    
    if let documentURL = Bundle.main.url(forResource: pdfName, withExtension: "pdf") {
        if let document = PDFDocument(url: documentURL) {
           
            pdfView.autoScales = true
            pdfView.backgroundColor = UIColor.lightGray
            document.delegate = self
            pdfView.document = document
           pdfView.autoScales = true
            pdfView.minScaleFactor = 1.5
            pdfView.maxScaleFactor = 5 }}    
   

有人可以向我解释一下是否可以快速完成,如果可以,请指导我如何实现这一目标,我已经尝试了很多搜索,但还没有结果。

任何帮助将不胜感激。

提前致谢。

这是我的 pdf 表单的图像

Is there any way to find the current pdf content size.

For example:-

When user open the pdf file and fill some information in the pdf and click on submit button. Then how to check pdf content size means the content fill fully or not. If user not fully added the details, pending some TextFiled in the pdf, then we need to show alert "Please fill all the information."

   override func viewDidLoad() {
    super.viewDidLoad()
    
    setupNavigationBar()
    
    self.view.addSubview(pdfView)
    
    if let documentURL = Bundle.main.url(forResource: pdfName, withExtension: "pdf") {
        if let document = PDFDocument(url: documentURL) {
           
            pdfView.autoScales = true
            pdfView.backgroundColor = UIColor.lightGray
            document.delegate = self
            pdfView.document = document
           pdfView.autoScales = true
            pdfView.minScaleFactor = 1.5
            pdfView.maxScaleFactor = 5 }}    
   

Can someone please explain to me is it possible in swift if yes please guide me how to achieve this, I've tried lot of search but no results yet.

Any help would be greatly appreciated.

Thanks in advance.

Here the image of My pdf form

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

累赘 2025-01-16 20:43:52

如果我很好地理解这是以编程方式,请声明您的文本字段和按钮保存:

let firstTextfield: UITextField = {
    let tf = UITextField()
    tf.placeholder = "First Textfield"
    tf.backgroundColor = .white
    tf.textColor = .black
    tf.borderStyle = .roundedRect
    
    return tf
}()

let secondTextfield: UITextField = {
    let tf = UITextField()
    tf.placeholder = "Second Textfield"
    tf.backgroundColor = .white
    tf.textColor = .black
    tf.borderStyle = .roundedRect
    
    return tf
}()

let thirdTextfield: UITextField = {
    let tf = UITextField()
    tf.placeholder = "Third Textfield"
    tf.backgroundColor = .white
    tf.textColor = .black
    tf.borderStyle = .roundedRect
    
    return tf
}()

let saveDataButton: UIButton = {
    let b = UIButton()
    b.backgroundColor = .white
    b.setTitle("Save", for: .normal)
    b.setTitleColor(.black, for: .normal)
    b.titleLabel?.font = .systemFont(ofSize: 17, weight: .semibold)
    b.layer.cornerRadius = 12
    b.clipsToBounds = true
    
    return b
}()

现在在 viewDidLoad 中声明 stackView 并设置约束:

view.backgroundColor = .black
    
    saveDataButton.addTarget(self, action: #selector(controlTextInTextfields), for: .touchUpInside) // call control function
    
    let staxkView = UIStackView(arrangedSubviews: [firstTextfield, secondTextfield, thirdTextfield, saveDataButton])
    staxkView.axis = .vertical
    staxkView.distribution = .fillEqually
    staxkView.spacing = 6
    staxkView.translatesAutoresizingMaskIntoConstraints = false
    
    view.addSubview(staxkView)
    staxkView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20).isActive = true
    staxkView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 20).isActive = true
    staxkView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -20).isActive = true
    staxkView.heightAnchor.constraint(equalToConstant: 218).isActive = true // height of all textfields, button and space

之后编写您的控件功能:

@objc func controlTextInTextfields() {
    if firstTextfield.text == "" || secondTextfield.text == "" || thirdTextfield.text == "" {
        print("no text in one of Textfields!")
    } else {
        print("All TF contains text!")
    }

如果您不太理解,请打开新文件并复制并粘贴我的代码

If I understand well this is programmatically way, declare your textfields and button Save:

let firstTextfield: UITextField = {
    let tf = UITextField()
    tf.placeholder = "First Textfield"
    tf.backgroundColor = .white
    tf.textColor = .black
    tf.borderStyle = .roundedRect
    
    return tf
}()

let secondTextfield: UITextField = {
    let tf = UITextField()
    tf.placeholder = "Second Textfield"
    tf.backgroundColor = .white
    tf.textColor = .black
    tf.borderStyle = .roundedRect
    
    return tf
}()

let thirdTextfield: UITextField = {
    let tf = UITextField()
    tf.placeholder = "Third Textfield"
    tf.backgroundColor = .white
    tf.textColor = .black
    tf.borderStyle = .roundedRect
    
    return tf
}()

let saveDataButton: UIButton = {
    let b = UIButton()
    b.backgroundColor = .white
    b.setTitle("Save", for: .normal)
    b.setTitleColor(.black, for: .normal)
    b.titleLabel?.font = .systemFont(ofSize: 17, weight: .semibold)
    b.layer.cornerRadius = 12
    b.clipsToBounds = true
    
    return b
}()

Now in viewDidLoad declare stackView and set constraints:

view.backgroundColor = .black
    
    saveDataButton.addTarget(self, action: #selector(controlTextInTextfields), for: .touchUpInside) // call control function
    
    let staxkView = UIStackView(arrangedSubviews: [firstTextfield, secondTextfield, thirdTextfield, saveDataButton])
    staxkView.axis = .vertical
    staxkView.distribution = .fillEqually
    staxkView.spacing = 6
    staxkView.translatesAutoresizingMaskIntoConstraints = false
    
    view.addSubview(staxkView)
    staxkView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20).isActive = true
    staxkView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 20).isActive = true
    staxkView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -20).isActive = true
    staxkView.heightAnchor.constraint(equalToConstant: 218).isActive = true // height of all textfields, button and space

After that write your control func:

@objc func controlTextInTextfields() {
    if firstTextfield.text == "" || secondTextfield.text == "" || thirdTextfield.text == "" {
        print("no text in one of Textfields!")
    } else {
        print("All TF contains text!")
    }

If you don't understand well, open new file and copy and paste my code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文