Pregunta

I am using VFR reader to display my pdf's. I need to extract the Table of Contents on a button click and display it in a tableview then it should lead to the respective pages while tapping on each.I googled for this and got these links

  1. Create a table of contents from a pdf file
  2. http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-adding-a-table-of-contents-to-an-ipad-reader/

And i came to know that, to get TOC we must use "CGPDFDocumentGetCatalog(pdf doc)". But in my reader that "CGPDFDocumentGetCatalog(pdf doc)" is not at all getting called. Now how can i extract my TOC from my pdf file? Kindly help me out of this. I am struggling on this for a week. Thanks in advance.

¿Fue útil?

Solución

Unfortunately I think the two answers you refer to point to different implementation strategies, which are both possibly valid but are different.

The first question is what the PDF files you have and want to show in your app look like. There is no such thing as a predefined TOC object in a PDF file, there are simply different ways to emulate this. The two most common ways are:

A) Bookmarks, which are a way to add little pieces of text to a structured tree, where each piece of text points to a specific location in the PDF file. These bookmarks can be added in the design application or later (there are specific tools to do so) and they can implement whatever structure.

B) Your PDF file might contain something that looks like a classic TOC from a book, which is basically just text on the opening pages, optionally with hyperlinks to specific locations in the book.

The second link you refer to shows how to create user interface where you can show the TOC in. The remaining question then is to figure out what items you want to display in the TOC window. In this second link you point to, the solution presented is to provide hard-coded items specific to one specific book. Of course this approach is not very useful when you want to display just any book.

So the question you are left with is how to figure out what items to display and where they link to.

If you consider my possibility A) above: a PDF file with bookmarks, the answer could be relatively simple. Answer 1 you point to explains how to look at the different structures inside a PDF file - bookmarks are simply such a structure (Defined in section 12.3 of the PDF specification: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf)

This means you could use the techniques shown there to walk the different objects in the PDF file, and find each bookmark. The bookmark will give you the text to display and the actual location in the PDF file that text should jump to when clicked.

If you consider my possibility B) above: a PDF file without bookmarks but a classic TOC, this will be much harder to solve. Such table of contents are simply text on one or more pages, optionally with hyperlinks. Of course you could try to find all text on these pages (if you can figure out on which page the TOC starts and ends), but you'd then also have to figure out where that item links to. If there are no hyperlinks involved, that would be a daunting task.

So your first question should be how generic you want to solve this problem. Do you know which PDF files you'll want to display? Can you devise a TOC for these files yourself (as in your solution 2)? If not, can you be sure all PDF files contain bookmarks? The answer to those questions will largely determine the rest of your strategy...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top