PDA

View Full Version : How to get PDF links from CGPDFDocument?




Max Gontar
Jul 16, 2010, 05:20 AM
Hello!

I'm trying to write a simple PDF viewer using CGPDFDocument (http://17.254.2.129/mac/library/documentation/GraphicsImaging/Reference/CGPDFDocument/Reference/reference.html), based on QuartzDemo.
There is common rendering:

-(void)drawInContext:(CGContextRef)context
{
// PDF page drawing expects a Lower-Left coordinate system,
// so we flip the coordinate system before we start drawing.
CGContextTranslateCTM(context, 0.0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);

// Grab the first PDF page
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, pageNumber);
// We're about to modify the context CTM to draw the PDF page
// where we want it, so save the graphics state
// in case we want to do more drawing
CGContextSaveGState(context);
// CGPDFPageGetDrawingTransform provides an easy way to get the
// transform for a PDF page. It will scale down to fit, including any
// base rotations necessary to display the PDF page correctly.
CGAffineTransform pdfTransform =
CGPDFPageGetDrawingTransform(page,
kCGPDFCropBox, self.bounds, 0, true);
// And apply the transform.
CGContextConcatCTM(context, pdfTransform);
// Finally, we draw the page
// and restore the graphics state for further manipulations!
CGContextDrawPDFPage(context, page);
CGContextRestoreGState(context);
}

As I understand, its only drawing, so all structure navigation or outgoing links should be handled manually (ex. in touch event).

There are functions which will set URL (http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/CGPDFContext/Reference/reference.html#//apple_ref/doc/uid/TP30000957-CH1g-BCIIBJGC) or create element with URL (http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/CGPDFContext/Reference/reference.html#//apple_ref/doc/uid/TP30000957-CH1g-F17184).

Question is: how to get outgoing link URL from certain PDF block?

Thank you!

Similar questions:
PDF hyperlinks on iPhone/iPad (http://stackoverflow.com/questions/2609602/pdf-hyperlinks-on-iphone-ipad)
How to access hyperlinks in PDF documents (iPhone)? (http://stackoverflow.com/questions/1247792/how-to-access-hyperlinks-in-pdf-documents-iphone)