4

Is there a way to retrieve text coordinates from PDF file on iPhone?

Thanks,

Nava.

More details: I'm trying to get words from pdf file and highlight them. While it's a pretty simple task in Mac OS X, which has a PDFKit, it's not that trivial on iPhone, which has Quartz set of functions to present and get information from pdf file. So far I tried and succeed in following - get words list from pdf file scanning its content and using Tj and TJ operators (see how to search text in pdf). While Tj gives a string and I can get words from it, TJ is an array of glyphs probably, since most of its members come as a single characters, but connecting them together still gives a string and I can get words from there.

My problem now is to highlight found words, which may be can be done by finding a TD/Td operators and trying to calculate character boxes by myself, but for this I need probably to get a font/style and other characteristics of glyphs to be able to calculate glyph boxes properly. And probably somehow to build a transformation matrix or something like this... Anybody can shed some light?

Nava Carmon
  • 4,523
  • 3
  • 40
  • 74
  • Please describe in more detail and with examples what you are trying to do and what your problem is. – DarkDust Oct 16 '10 at 19:56
  • can you please give me some suggestion regarding the pdf search and highlight word http://stackoverflow.com/questions/5354457/text-selection-on-pdf-after-rendering-in-iphone – ajay Mar 21 '11 at 11:46
  • http://stackoverflow.com/questions/5335799/is-there-any-framework-to-highlight-text-on-pdf-file-after-rendering – ajay Mar 21 '11 at 11:46

2 Answers2

1

solved with open source poppler library

Nava Carmon
  • 4,523
  • 3
  • 40
  • 74
  • Please tell me the exact procedure to build the poppler library on mac. I am stuck with the build procedure. It gives me config.h file not found error with many other errors when i try to build poppler library using xcode. – CKT Dec 01 '10 at 12:22
  • I didn't need it all, so i took ONLY files that are needed for my purpose. If you need to build it for mac, use make files, it builds as is – Nava Carmon Dec 01 '10 at 12:33
  • Hi thanks for your immediate reply. I tried to build the library from MAC terminal. but no success. I actually want a parsing library to search text and highlight it in pdf on ipad. The Core graphics support didnot give me the position of the searched text as mentioned above. So i switched to the use of poppler. But I am not very clear how to go about using this in my ipad project to highlight the search text. Would you please guide me. Which files from the poppler code do we need? Including files from poppler, goo and utils folder gives me compilation error. – CKT Dec 01 '10 at 14:19
  • @chaitanya, you need first to be able to build it for mac. There is a file, called INSTALL, which explains in detail what do you need there. I don't think SO comment is a good place to put an explanation, since it's very lengthy. First try to build it for mac and to build an xcode project, that uses it. – Nava Carmon Dec 01 '10 at 14:50
  • can you please provide me the procedure http://stackoverflow.com/questions/5335799/is-there-any-framework-to-highlight-text-on-pdf-file-after-rendering – ajay Mar 21 '11 at 11:47
  • Hi, I am stuck in poppler library please can you give me any example or link which can help me.I don't know how to include that library in iphone project or how to use. Any help will be appreciated. Thanks –  Nov 22 '10 at 13:34
  • First build a freetype library for iPhone, there is a post, describing it (google for it, I cannot find the link :(). Second, I created a new project with static library template for iPhone and put there ONLY files from poppler, that I need for the described purpose. I took them from poppler library itself. Hopefully it helps – Nava Carmon Nov 23 '10 at 20:52
  • poppler is GPL. Where can I download your app's sourcecode? http://cgit.freedesktop.org/poppler/poppler/tree/COPYING – steipete Jul 21 '11 at 22:26
  • That's interesting, it wasn't GPL at the time I used it. Can I upload it here? – Nava Carmon Jul 24 '11 at 07:13
  • No, you really have to provide it somewhere. I'll propose GitHub, which works great. As Poppler is a fork of XPdf which itself is GPL too, I can't believe that it was on a less restrictive license when you started working with it. Further, if any of the authors of Xpdf or Poppler decide that they don't want your app to use it, they can let you be removed from the AppStore. Just google what happened to VLC/iOS. – steipete Nov 19 '11 at 12:58
  • I really have to find some time to do it. Will try to post it in a nearest week. – Nava Carmon Nov 20 '11 at 07:51
0

I have been trying to do the same but it's too technical to build a parser myself. Then I found FastPDFKit open source sdk recently. There is a free version with sample iOS project that includes search and highlight.

http://mobfarm.eu/fastpdfkit

After reading the other answers I will start exploring Poppler too. If someone has a sample project please let me know :)

topace
  • 1,791
  • 3
  • 17
  • 23