2

I have implemented an iPad application which is actually read the PDF file(using quartz). Now I want to implement the Search Feature and for this I have checked some tutorial some where mentioned using quartz and some where mentioned FastPdfKit. But I don't know which one will be better. I have seen the quartz ( https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf_scan/dq_pdf_scan.html ). I have some doubt in this.

  1. the "Callbacks for Operators" what and why we use this?
  2. "Operators Table" what is the purpose of this? and
  3. Where we will put the search text.

Please suggest me in this regards or provide any other open source which I can use.

Thanks in advance.

Subodh S
  • 41
  • 1
  • 5

3 Answers3

3

CGPDFScanner is a fairly low-level API which allows you to selectively scan for various PDF operators and invoke callbacks on each operator. It does require you to have some knowledge of PDF structure, but it will do the job. A PDF operator is a command in a PDF file which does some operation (usually manipulating the drawing state, e.g. writing text, drawing lines, changing graphics state, etc.).

Essentially, you tell the scanner what PDF operators you are interested in, and tell it what callback you want to invoke. In your case, you are interested in the text operators TJ, Tj; see this page for a working text search example using this API, and this question for some other answers on text search.

Community
  • 1
  • 1
nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • Is there any sample code/app which will fulfill the search function. step wise guide. – Subodh S Aug 28 '12 at 07:14
  • Yes I have seen this. Is there any sample application? – Subodh S Aug 28 '12 at 07:16
  • 1
    Well, he gives you (1) code to read each page of a PDF and (2) code to scan a PDF for a desired text string (even nicely wrapped in a class). If you try to understand the post I think you can easily make your own sample application. – nneonneo Aug 28 '12 at 07:23
  • Which variable is responsible to take the search text e.g search text is: iOS application... is this "inSearchString"? – Subodh S Aug 28 '12 at 07:43
  • Look at his "actual search method", at the bottom. There you will see how to input the search text. Please read that blog post carefully: it is very useful! – nneonneo Aug 28 '12 at 07:44
  • Hi I have used that code and call by CGPDFPageRef singlePage = CGPDFDocumentGetPage(book, 3); pdfsearch = [[PDFSearcher alloc] init]; [pdfsearch page:(CGPDFPageRef)singlePage containsString:(NSString *)searchString]; NSLog(@"ALl Search String:%@",pdfsearch.currentData); Out put in console: % Q P V G P V U + P V T Q F W E V K Q P + P V T Q F W E V K Q P ˙ 1 T I C P K \ C V K Q P Q H 6 J K U & Q E W O G P V ˙ + P U V C N N K P I V J G K 1 5 5 &- Please let me know what's this? – Subodh S Aug 29 '12 at 09:41
  • Hi Please let me know what exactly it is? – Subodh S Sep 04 '12 at 05:26
  • Hi, I have got this output which is search from a single page PDF. Please let me know what is this? ALl Search String: K 1 5 & G X G N Q R O G P V ) W K F G 6 Q Q N U . C P I W C I G U ˝ + & ' U – Subodh S Sep 04 '12 at 14:10
  • seems the link with block want work for current time. can you update answer with some new links? I also found this https://github.com/leberwurstsaft/Crawl/blob/master/Classes/PDFSearcher.m maybe this is what about you said. – Matrosov Oleksandr Sep 20 '14 at 19:02
  • @MatrosovAlexander: Thanks for letting me know. I have updated the link using the Wayback Machine. – nneonneo Sep 20 '14 at 20:40
  • @nneonneo no problem, do you have any suggestion about annotation and highlight text? Maybe you can suggest something here on my questions as well: http://stackoverflow.com/questions/23920377/ios-cgpdf-highlight-text-using-cgrect http://stackoverflow.com/questions/24189458/ios-how-to-get-all-words-coordinates-in-pdf-page – Matrosov Oleksandr Sep 20 '14 at 20:54
1

You may get your answer at FastPdfKit. Please let me know if you still more information. I think this will solve your purpose.

BornCoder
  • 1,046
  • 8
  • 10
  • I don't want to use the whole FastPdfKit project. I need only the Search feature from that is this possible? – Subodh S Aug 28 '12 at 07:13
  • You also have look at [PDFKitten](https://github.com/KurtCode/PDFKitten). You can get functionality using this code. – BornCoder Aug 28 '12 at 07:15
  • I have checked this one and found it will display only one word search not a string e.g. "iOS" not "iOS Development". I have done some part using blog.random-ideas.net/?p=184 and call the function CGPDFPageRef singlePage = CGPDFDocumentGetPage(book, 3); pdfsearch = [[PDFSearcher alloc] init]; [pdfsearch page:(CGPDFPageRef)singlePage containsString:(NSString *)searchString]; NSLog(@"ALl Search String:%@",pdfsearch.currentData); And I have got this output. Please let me know what is this? ALl Search String: K 1 5 & G X G N Q R O G P V ) W K F G 6 Q Q N U . C P I W C I G U ˝ + & ' U – Subodh S Sep 05 '12 at 09:56
  • I am able to implement the search feature using PDFKitten. But in my PDF there is a text "St. Stephen's" and after "St. S" it shows an exception. Please let me know what's the problem in this string? – Subodh S Sep 13 '12 at 11:33
0

@Subodh S: At the momment, PDFKitten does not support multi-words query. Therefore, your keyword is not searched and highlighted. You must handle yourself in source code and even change some points in PDFKitten.

GooX
  • 29
  • 1
  • 2
  • 7