cooliphonedeveloper
cooliphonedeveloper

Reputation: 19

HIghlighting the text in PDF document iPhone xcode

Hii friends, i am developing a e Book using a web view where i am loading the web view with PDF document.Now i want to develop the search functionality but i am not unserstanding how to implement it.So kindly give me a solution,

Thanks in advance.

Upvotes: 2

Views: 9257

Answers (2)

Joe Yang
Joe Yang

Reputation: 1645

it seems not an easy work, here is my thought.

Instead of using CGContextDrawPDFPage in Quartz2D, you may need to layout the page yourself for getting the CGRect of the text for highlight.

  1. Parse PDF page content to PDF objects.
  2. Combine the PDF objects in binary form or other forms to the objects you can use in Core Text/CoreGraphics, like CTFontDescriptorRef, PDF operators binary streams
  3. Use Core Text/CoreGraphics function to layout the text/graphics from the fonts/text/images/pdf graphic operators, and then you can get the position and rect
  4. return a CGRect, and highlight that CGRect using CoreGraphics functions

Upvotes: 0

Alex Reynolds
Alex Reynolds

Reputation: 96927

Instead of using UIWebView, you might want to look into using Quartz 2D's CGPDFDocumentRef and parsing a CGPDFDictionary for strings of interest.

Once your know which PDF dictionary elements contain your text and where they are located, you might be able to highlight that text with other Quartz 2D routines.

Another option might be to convert your PDF document to RTF or HTML formats, either of which would probably be easier to parse and edit to add highlighting.

Upvotes: 3

Related Questions