9

Is it possible to get access to "internal" links in PDF documents using CGPDFDocument, or other means? I'm building a simple reader app and would like to deliver my content in PDF form, but if I can't support links between pages in the doc this probably isn't going to work.

This question is similar, but does not address the issue of how to support hyperlinks.

3
  • What exactly do you mean by links between pages? Are you talking about a link on page 1, which goes to page 4, or are you talking about page one being followed by page 2 in your reader? By the way, if you're talking about clickable links between pages, keep in mind that hyperlinks in a PDF document are simply clickable hotspot rectangles on a page and have no direct relationship with the text that they appear to hyperlink. A PDF document is not like a HTML document in that sense.
    – Rowan
    Commented Aug 8, 2009 at 6:51
  • I mean supporting links from one page to some other arbitrary page in the document. I would use this for a Table of Contents, as well as for referencing other pages in random places. So yes, what I am really looking for is an HTML-like way to navigate PDF docs. I can handle the simple case of "next/prev/home" navigation without this, but ideally I would like to also support arbitrary navigation. Thanks. Commented Aug 8, 2009 at 15:18
  • Here's some sample code, from my own question: stackoverflow.com/questions/4080373/…
    – ySgPjx
    Commented Nov 3, 2010 at 16:26

4 Answers 4

2

See my answer here. Basically, you'll need to get familiar with PDF link annotations.

1

see this sample code...pdf hyperlinks works in this

https://github.com/vfr/Reader

0

If you're using Quartz to open and view a PDF, then yes, it looks like you will have access to internal links. Quartz will also let you add new links to PDFs. I don't have any first hand experience with iPhone/Mac development, but it would be quite strange for them to let you add hyperlinks, but not use them.

3
  • 2
    These links both point to the Mac OS X reference library, not iPhone OS. PDFKit doesn't exist on the phone. Commented Feb 24, 2010 at 14:23
  • Yes above both link are just opening list of osx reference libraries. It doesn't give any proper info. How it is accepted ? -1 Commented Mar 4, 2010 at 8:24
  • Sorry folks, I'm not doing iPhone dev anymore, so this is effectively an abandoned question. I'm unable to verify whether this is an acceptable answer or not, so I've just "unaccepted" it. Commented Jul 10, 2010 at 13:17
0

You need to do in two steps.

First: Parse your pdf to locate marked content operators

That's an exemple of a parsing code :

-(void)parseContent() {
    CGPDFOperatorTableRef myTable;
    myTable = CGPDFOperatorTableCreate();
    CGPDFOperatorTableSetCallback(myTable, "BMC", &myOperator_BMC);
    CGPDFContentStreamRef myContentStream = CGPDFContentStreamCreateWithPage(page);
    CGPDFScannerRef myScanner = CGPDFScannerCreate(myContentStream, myTable, autoZoomAreas);
    CGPDFScannerScan(myScanner);
    CGPDFScannerRelease(myScanner);
    CGPDFContentStreamRelease(myContentStream); 
}

void myOperator_BMC(CGPDFScannerRef s, void *info)
{
    const char *name;
    CGPDFScannerPopName(s, &name);
}

(You need to complete and adjust this code to match your requirement)

Second: respond to the toucheEnded message to handle tap on those zones and make the UI respond accordingly.

Not the answer you're looking for? Browse other questions tagged or ask your own question.