我可以以编程方式向 PDF 添加链接注释吗? [英] Can I programmatically add link annotation to PDFs?

查看:40
本文介绍了我可以以编程方式向 PDF 添加链接注释吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个使用 UIWebView 显示 PDF 的 iPad 应用程序.我有一个 PDF,我想以编程方式向其中添加链接.为简单起见,假设有 10 个段落.它们都有编号,并且有几行文本.我希望能够以某种方式向 PDF 添加一个基本链接,以便如果第 2 段被触摸,那么我的 UIWebView 可以处理与第 2 段关联的请求.

I am making an iPad app that uses UIWebView to display PDFs. I have a PDF that I would like to programmatically add links to. For simplicity, lets say there are 10 paragraphs. They are all numbered and have a few lines of text in them. I want to be able to somehow add a basic link to the PDF so that if paragraph 2 is touched, then my UIWebView can process the request that is associated with paragraph 2.

我不知道 PDF 的内部结构是什么样的.我不知道如何将其缩放到数百页的每个段落.但我想知道我是否可以以某种方式向 PDF 添加链接或 HTML,以便我可以使用我的应用程序对其进行操作.

I have no idea what the structure of the PDF is like on the inside. I have no clue how to scale this to each paragraph of several hundred pages. But I am wondering if I can somehow add a link or HTML to the PDF so that I can manipulate it with my app.

谢谢!

明确地说,我正在 iOS 设备上查看此 PDF,但我意识到我的问题的解决方案可能与 Cocoa-touch 框架无关.我正在寻找任何类型的解决方案,使我能够向 PDF 的某些区域添加不可见的链接.

To be clear, I am viewing this PDF on an iOS device but I recognize that the solution to my question might not have anything to do with Cocoa-touch frameworks. I am looking for any sort of solution that will allow me to add invisible links to certain areas of my PDF.

推荐答案

如果您希望 iPad 应用能够识别 pdf 中的文本字段、按钮和链接.您可以编辑实际的 pdf(您需要一个 Adob​​e Acrobat 版本)并将这些字段添加到 pdf 中.在您的 ios 代码中,使用以下内容解析 pdf 字段:

If you want an iPad app to recognize text fields, buttons, links from a pdf. You can edit the actual pdf (you'll need a version of Adobe Acrobat) and add those fields to the pdf. In your ios code parse the pdf fields using something like:

在解析方法中:

    -(void)parse:(CGPDFPageRef)page
{
    for (int i = 0; i < CGPDFArrayGetCount (annotations); i++)

CGPDFArrayGetCount 返回 PDF 数组中的项目数.

CGPDFArrayGetCount returns the number of items in a PDF array.

在循环中获取字段名称:

in the loop grab the field name:

    if (CGPDFDictionaryGetString(dict, "T", &stringRef))
    {
        char *s = (char *) CGPDFStringGetBytePtr(stringRef);
        fieldName = [NSString stringWithCString:s encoding:NSUTF8StringEncoding];
    }

如果字段名称匹配,请检查您要执行的操作,例如button_1"或hlink_3":

check to see what you want to do if a field name matches, say "button_1" or "hlink_3":

    if ([fieldName isEqualToString:@"hlink_3"])
{
        // do whatever, example add a button where the field was
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = rect;
        [self addSubview:button];
}

还有很多内容,但这是总体思路.

There's a lot more to it, but this is the general idea.

这篇关于我可以以编程方式向 PDF 添加链接注释吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆