iPhone、CGPDF文档 - PDF 链接

发布于 2024-09-10 00:11:51 字数 3048 浏览 0 评论 0原文

我正在尝试使用 CGPDFDocument 编写一个简单的 PDF 查看器,基于QuartzDemo。
有常见的渲染:

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

据我了解,它是唯一的绘图,因此所有结构导航或传出链接都应手动处理(例如在触摸事件中)。

有函数 将设置 URL使用 URL 创建元素

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

谢谢!

类似问题:
iPhone/iPad 上的 PDF 超链接
如何访问 PDF 文档 (iPhone) 中的超链接?

相同上
iPhone SDK 开发小组
macRumors 论坛
iPhone 开发SDK论坛
开发棚论坛
iphonedevbook.com

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).

There are functions which will set URL or create element with URL.

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

Thank you!

Similar questions:
PDF hyperlinks on iPhone/iPad
How to access hyperlinks in PDF documents (iPhone)?

Same on
iPhone SDK Dev GGroup
macRumors Forum
iPhone Dev SDK Forum
Dev Shed Forum
iphonedevbook.com

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖哒 2024-09-17 00:11:51

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

在非常粗略的伪代码中:

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

Adobe 发布了一份文档,列出了 PDF 规范。祝你好运!

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.

In very rough pseudo code:

  • use CGPDFDocumentGetCatalog to get the catalog for the PDF
  • look in the "pages" element of the catalog for the page you're looking for (yes, it's a dictionary, not an array, and a nested one, so this simple operation is not-so-simple).
  • now use CGPDFDictionaryGetArray to get the "Annots" object
  • next, you need to iterate through the annotations and look for "Link" objects.

Adobe has published a document that lays out the PDF specification. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文