Home > Net >  Check PDF Content Size and show alert Swift
Check PDF Content Size and show alert Swift

Time:03-01

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."

Code:-

override func viewDidLoad() {
    super.viewDidLoad()
    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
        }
    }
}

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.

CodePudding user response:

I found solution to check PDF Content.

Code:-

func checkPDFTextFiledDataBlankOrNot() {
    if let page = pdfVw.document?.page(at: 0){
        let annotations = page.annotations
        for annotation in annotations{
            if annotation.widgetStringValue == " "{
                annotation.widgetStringValue = "N/A"
                emptyTxtFields  = 1
            }else {
                fillTxtfields   = 1
            }
        }
    }
}
  • Related