问题描述
我正在尝试使用 CGPDFDocument,基于 QuartzDemo.
有常见的渲染:
I'm trying to write a simple PDF viewer using CGPDFDocument, 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).
有函数 这将设置 URL 或 创建带有 URL 的元素.
问题是:如何从某个 PDF 块中获取传出链接 URL?
谢谢!
类似问题:
iPhone/iPad 上的 PDF 超链接
如何访问 PDF 文档中的超链接 (iPhone)?
同上
iPhone SDK 开发 GGroup
macRumors 论坛
iPhone 开发SDK论坛
开发棚论坛
iphonedevbook.com
推荐答案
这是一个重要的问题,这就是为什么您找不到简单的答案.解决方案是:您必须解析PDF文档.好消息是,Apple 提供了一些功能可以让您做到这一点.坏消息是,它们是程序性的,伙计,这是一个令人费解的混乱.
This is a non-trivial question, which is why you've found no easy answer. The solution is: you have to parse the PDF document. The good news is, there are functions provided by Apple to allow you do to this. The bad news is, they're procedural, and man, is it a convoluted mess.
非常粗略的伪代码:
- 使用 CGPDFDocumentGetCatalog 获取 PDF 的目录
- 在目录的pages"元素中查找您要查找的页面(是的,它是字典,不是数组,并且是嵌套的,因此这个简单的操作并不那么简单).
- 现在使用 CGPDFDictionaryGetArray 来获取Annots"对象
- 接下来,您需要遍历注释并查找链接"对象.
Adobe 发布了一份 文档,其中列出了 PDF 规范.祝你好运!
Adobe has published a document that lays out the PDF specification. Good luck!
这篇关于iPhone, CGPDFDocument - PDF 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!