views:

1012

answers:

5

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.

+2  A: 

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.

Alex Reynolds
A: 

hey alex thanks for the help,But i have never used CGPDFDocumentRef and CGPDFDictionary.So if you can give me some example or the tutorial on how to use this two,it would be of great help,Thanks a lot for this reply,

cooliphonedeveloper
A: 

also u said to convert the PDF file into html or rtf file which is difficult to do because for that i need to get the PDF contents into the string.I am copying the PDF contents into string but it is giving junk values,

cooliphonedeveloper
A: 

But how would you know where it is located? In other words, when scanner calls our callback, how can we get the supposed coordinates of text?

A: 

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
Joe Yang