SaraAwad
SaraAwad

Reputation: 31

PdfKit Annotations Highlight & Save IOS 11

Is there any helpful walkthrough on how to use the pdfkit annotations(highlight, comments, etc..) and save the results in swift.

I couldn’t find a helpful one.

Thank you

Upvotes: 0

Views: 1101

Answers (1)

Mahesh Shahane
Mahesh Shahane

Reputation: 499

For Highlight you can use following code :

let selections = self.pdfview.currentSelection?.selectionsByLine()
// Simple scenario, assuming your pdf is single-page.
guard let page = selections?.first?.pages.first else { return }

if selections == nil {

}else {

    selections?.forEach({ selection in

        let highlight = PDFAnnotation(bounds: selection.bounds(for: page), forType: .highlight, withProperties: nil)
        //            highlight.endLineStyle = .square

        highlight.color = UIColor(red:0.49, green:0.99, blue:0.00, alpha:1.0).withAlphaComponent(0.5)
            page.addAnnotation(highlight)
    })
}

For Save :

self.pdfdocument?.write(to: urlPath!)

Upvotes: 1

Related Questions