我在使用 pdf 上的 GOTOR 链接获取外部文件的地址时遇到问题。使用 quartz 。 我从苹果开发者区得到了一些例子,并且实际上能够得到直到数据字典中的 GOTOR 入口:这是我使用的代码:
if (strcmp(actionType, "GoToR") == 0) // GoTo action type
{
NSLog(@"Annotation is of type GotoR");
if (CGPDFDictionaryGetArray(actionDictionary, "D", &destArray) == false)
{
const char *actionFile = NULL; // Annotation action type string
CGPDFDictionaryGetName(actionDictionary, "F", &actionFile);
CGPDFDictionaryGetString(actionDictionary, "D", &destName);
NSLog(@"link is %@ filename is:%s",CGPDFStringCopyTextString(destName),actionFile);
}
}
单击链接,我从 NSLOG 中得到以下输出:
链接是 REF-0000059 文件名是:(空)
在 PDF 格式引用中指出 GOTOR 注释应该有一个 F 字段,其中包含指向目标文件的链接...任何人都知道我做错了什么?
最好的问候。
最佳答案
对于可能对该解决方案感兴趣的任何人: GOTOR F 字段既可以是字符串,也可以是数组,因此要使其在每种情况下都能正常工作,我们必须检查这两种可能性:
if (strcmp(actionType, "GoToR") == 0) // GoTo action type
{
NSLog(@"Annotation do tipo GotoR");
if (CGPDFDictionaryGetArray(actionDictionary, "D", &destArray) == false)
{
CGPDFStringRef actionFile = NULL;
CGPDFDictionaryRef linkDictionary = NULL;
if (CGPDFDictionaryGetDictionary(actionDictionary, "F", &linkDictionary) == true){
CGPDFDictionaryGetString(linkDictionary, "F", &actionFile);
}
else{
CGPDFDictionaryGetString(actionDictionary, "F", &actionFile);
}
*actionFile = NULL; // Annotation action type string
CGPDFDictionaryGetString(actionDictionary, "D", &destName);
NSLog(@"link is %@ filename is:%@",CGPDFStringCopyTextString(destName),CGPDFStringCopyTextString(actionFile));
}
}
关于iphone - IOS解析PDF和GOTOR链接的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7407684/