How to access hyperlinks in PDF documents (iPhone)?
Asked Answered
P

4

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.

Promiscuity answered 8/8, 2009 at 2:33 Comment(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.Mull
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.Promiscuity
Here's some sample code, from my own question: #4080873Bourbonism
L
2

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

Lift answered 9/8, 2010 at 22:35 Comment(0)
P
1

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

https://github.com/vfr/Reader

Parry answered 8/9, 2011 at 10:40 Comment(0)
M
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.

Mull answered 11/8, 2009 at 2:6 Comment(3)
These links both point to the Mac OS X reference library, not iPhone OS. PDFKit doesn't exist on the phone.Early
Yes above both link are just opening list of osx reference libraries. It doesn't give any proper info. How it is accepted ? -1Freeness
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.Promiscuity
C
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.

Confrere answered 31/8, 2010 at 10:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.