我可以以编程方式向PDF添加链接注释吗? [英] Can I programmatically add link annotation to PDFs?
问题描述
我正在制作一个使用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结构如何.我不知道如何将其缩放到数百页的每个段落.但是我想知道是否可以以某种方式将链接或HTML添加到PDF,以便可以使用我的应用程序对其进行操作.
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(您需要一个Adobe 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屋!