iPhone、CGPDF文档 - PDF 链接

标签 iphone cocoa-touch pdf hyperlink quartz-2d

我正在尝试使用 CGPDFDocument 编写一个基于 QuartzDemo 的简单 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 block 获取传出链接 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

最佳答案

这是一个重要的问题,这就是为什么您找不到简单的答案。解决办法是:你必须解析PDF文档。好消息是,Apple 提供了一些功能可以让您做到这一点。坏消息是,它们是程序性的,伙计,这是一团困惑。

非常粗略的伪代码:

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

Adobe 发布了 document列出了 PDF 规范。祝你好运!

关于iPhone、CGPDF文档 - PDF 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3257057/

相关文章:

iphone - 减少关于 NSTimer 的分数

java - 如何使用pdfbox获取页面内容高度

dictionary - 有什么方法可以将字典连接到 Linux 中的 pdf 阅读器吗?

ios - 如何确定文件是否为 zip 文件?

ios - 在 UIButton 中使用 UIBarButtonItem 图标

iOS:使用 PDF 下载的应用程序,建议使用哪种方法? (ftp,休息, SOAP ,..)

iphone - 当有人给您打电话/发短信时暂停游戏

iphone - cocoa touch -- 测试对象是否是 objective-C 对象

iphone - iPhone 应用程序中的 map 集成

objective-c - 使用触摸移动事件移动 CALayer