I am working on a PDF Reader app in iOS 11 swift. I need to highlight text and scribble using ink annotations. I've been using iOS PDFKit framework but I can't find a sample implementation of these.
Asked
Active
Viewed 1,347 times
1
-
Apple doesn't offer UI to create ink or highlight annotations. There are several 3rd-party commercial solutions available to fill in the gap, like https://pspdfkit.com/guides/ios/current/migration-guides/migrating-from-apple-pdfkit/ – steipete Aug 14 '18 at 07:03
2 Answers
3
You can use PdfKit Annotation: (you have select some text before execute this method)
PDFSelection *select = [[PDFSelection alloc] initWithDocument:_pdfView.document];
[select addSelection:_pdfView.currentSelection];
NSArray *arrayByLine = _pdfView.currentSelection.selectionsByLine;
for (PDFSelection *select in arrayByLine) {
PDFAnnotation *annotation = [[PDFAnnotation alloc] initWithBounds:[select boundsForPage:_pdfView.currentPage] forType:PDFAnnotationSubtypeHighlight withProperties:nil];
annotation.color =[UIColor yellowColor];
[_pdfView.currentPage addAnnotation:annotation];
}
There is a lot of annotation you can use:
PDFAnnotationSubtypeUnderline
PDFAnnotationSubtypeStrikeOut
PDFAnnotationSubtypeSquare
PDFAnnotationSubtypeCircle
PDFAnnotationSubtypeHighlight
.......
for swift user check this

Zouhair Sassi
- 1,403
- 1
- 13
- 30
0
Basically you need to check PDFKit Framework!
In PDFDocument class you will find below method
open func findString(_ string: String, withOptions options: NSString.CompareOptions = []) -> [PDFSelection]
This method will return you array of PDFSelection, which you can assign directly to PDFView using below method of PDFView Class
@available(iOS 11.0, *)
open var highlightedSelections: [PDFSelection]?

Saurabh Prajapati
- 2,348
- 1
- 24
- 42