2010-07-15 62 views
23

我想写一个简单的PDF阅读器,使用基于QuartzDemo的CGPDFDocument
有共同的描绘:(EX在触摸事件)iPhone,CGPDFDocument - PDF链接

-(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); 
} 

据我了解,它唯一的图纸,所以所有的结构导航或外向链接,应手工处理。有功能which will set URLcreate element with URL

问题是:如何从某个PDF块中获取传出链接URL?

谢谢!

类似的问题:
PDF hyperlinks on iPhone/iPad
How to access hyperlinks in PDF documents (iPhone)?

相同的
iPhone SDK Dev GGroup
macRumors Forum
iPhone Dev SDK Forum
Dev Shed Forum
iphonedevbook.com

+2

对于任何地方都没有答案的问题+1。 *擦头,不断挖掘* – Kalle 2010-08-27 08:56:12

+3

+1,50点赏金 - 我很想知道答案,我们一直在寻找几个星期,不管我们已经尝试过什么没有结果 – 2010-09-27 23:45:19

+2

+100分为工作样品! – 2010-10-05 05:12:07

回答

17

这是一个不平凡的问题,这就是为什么你找不到简单的答案。解决方案是:您必须解析PDF文档。好消息是,苹果提供的功能可以让你做到这一点。坏消息是,他们是程序性的,而男性,这是一团糟。

在非常粗糙的伪代码:

  • 使用CGPDFDocumentGetCatalog获得样本为PDF
  • 看在目录你正在寻找的页面(是的,它是在“页面”元素一个字典,而不是一个数组和一个嵌套的字典,所以这个简单的操作不是那么简单)。
  • 现在使用CGPDFDictionaryGetArray获取“Annot”对象
  • 接下来,您需要遍历注释并查找“Link”对象。

Adob​​e发布了一个document,它规定了PDF规范。祝你好运!

+0

谢谢我意识到这不是一个微不足道的问题,因此赏金,但它是非常重要的,苹果文档是非常差,关于iPhone上的Quartz PDF,并没有其他博客或教程覆盖它 – 2010-09-29 09:03:36