iOS How to get all words coordinates in PDF page

409 views Asked by At

I have looked through many tutorials and usually stack users trow links to the pdfkitten, but as I've tested it I have not satisfied with result. So the search does not work with multiply word and etc.

So what I am looking for I need to get all words from the pdf page and highlight it if the words cross some rectangle.

1

There are 1 answers

3
Swaroop On

I used PDFKitten for the same.

  • What I did was while scanning the PDF - Identify the words separated by spaces.
  • Save the RenderingState(Model in PDFKitten code)word is encountered save that word in a model with it's current RenderingState (Model in PDFKitten code) which will be initial state. When the complete word is found(space separated) again save the current RenderingState as final state.
  • The code for converting RenderingState to actual view's frame using above initial state and final state, is present in PDFKitten. You can refer to that code.
  • apply current media box transform to frame.
  • And finally don't forget to convert resulted frame into user's co-ordinate system. Otherwise you will observe the reverse effect.