9
votes

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.

4
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
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.George Armhold
Here's some sample code, from my own question: stackoverflow.com/questions/4080373/…ySgPjx

4 Answers

2
votes

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

1
votes

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

https://github.com/vfr/Reader

0
votes

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.

0
votes

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.