SkillAgentSearch skills...

PDFReader

✏️ IOS 11 | PDFKit | IFiles | ICloud

Install / Use

/learn @ivankholod/PDFReader
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

PDFReader - Smart PDF Reader and Editor

alt text

Description

  • Now it work only for all IPads, because i used UIPopovers. (You can change it, if you want)
  • User can open PDFDocuments from native iOS application "Files"
  • PDFDocument automatically saved and synchronizes in ICloud.
  • User can highlighted annotation for selected area which finger determined.
  • If you want delete annotations - turn on "Pencil Mode" and tap to area!

How it works?

  • I used native PDFKit:

    • https://developer.apple.com/documentation/pdfkit
  • For work with documents: UIDocumentPickerViewController:

    • https://developer.apple.com/documentation/uikit/uidocumentpickerviewcontroller
  • Highlighted text: UITouch and PDFSelection:

    • UITouch dont called when PDFDocument is open.
    • I solved this problem. (Read the text below)
  • Handle UITouchDelegate:

    • Put subview on PDFView when user turn on "Pencil Mode"
    • Subiew removed from super view when called method: UITouchEnded
    • Use property:
        @property (assign, nonatomic) CGPoint startPoint;
        @property (assign, nonatomic) CGPoint currentMovePoint;
        @property (assign, nonatomic) CGPoint endPoint;
       
    
  • In touchesBegan: method we will get the coordinates of the first point.

  • ❗️ Dont forget! PDFPage and UIVew - different coordinate systems

    • Call this method for convert points from UIView to PDFView page.
    [PDFView* view convertPoint:point toPage:self.readerPDF.currentPage]
     -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
       [super touchesBegan:touches withEvent:event];
   
       UITouch *touch = [touches anyObject];
   
       CGPoint point = [touch locationInView:self.viewForTouch];
   
       self.startPoint = [self.readerPDF convertPoint:point toPage:self.readerPDF.currentPage];
     
     }
  • In touchesMoved: method we will get the coordinates of the moved point.
   -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
     [super touchesMoved:touches withEvent:event];
 
     UITouch *touch = [touches anyObject];
     CGPoint point = [touch locationInView:self.viewForTouch];
 
     self.endPoint = [self.readerPDF convertPoint:point toPage:self.readerPDF.currentPage];
     self.currentMovePoint = [self.readerPDF convertPoint:point toPage:self.readerPDF.currentPage];
 
     PDFSelection* selection = [self.readerPDF.currentPage selectionFromPoint:self.startPoint toPoint:self.currentMovePoint];
     
     NSArray* arraySelections = [selection selectionsByLine];
 
     [self.readerPDF setHighlightedSelections:arraySelections];
     [self.readerPDF setCurrentSelection: selection];

 }
  • In touchesEnded: method:
  -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
     [super touchesEnded:touches withEvent:event];
 
     UITouch *touch = [touches anyObject];
     CGPoint point = [touch locationInView:self.viewForTouch];
 
     self.endPoint = [self.readerPDF convertPoint:point toPage:self.readerPDF.currentPage];

     PDFSelection* selection = [self.readerPDF.currentPage selectionFromPoint:self.startPoint toPoint:self.endPoint];
 
     NSArray* array = [selection selectionsByLine];
 
         for (PDFSelection* select in array) {
 
             PDFAnnotation* annotation = [[PDFAnnotation alloc] initWithBounds:[select boundsForPage:self.readerPDF.currentPage] forType:PDFAnnotationSubtypeHighlight withProperties:nil];
             
             [self.readerPDF.currentPage addAnnotation:annotation];
         }
}

  • Well done! After this we get perfect PDFSelection. And add annotation to selections coordinats.

Examples:

Just select and autohighlight:

alt text

Also you can use colors from beautiful pallet color:

alt text

Look and navigate on all annotations:

alt text

Just Tap and Remove annotations! :

alt text

It's look so nice:

alt text

Related Skills

View on GitHub
GitHub Stars27
CategoryDevelopment
Updated15d ago
Forks4

Languages

Objective-C

Security Score

80/100

Audited on Mar 16, 2026

No findings