Problem with IOS parsing PDF and GOTOR links
I am having problems getting the address of an external file using GOTOR links on pdfs. using quartz. I got some examples from the apple developers area, and was actually able to get untill the GOTOR entrance on the data dictionary: here is the code I use:
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);
}
}
Clicking on the link, I get the following output from the NSLOG:
link is REF-0000059 filename is:(null)
In the PDF format reference stated that the GOTOR annotations should have a F field开发者_高级运维 with the link to the destination file... Anyone has any Ideas what I am doing wrong?
Best regards.
To anyone that might be interested in the solution: The GOTOR F field can be both a String, or an Array, so for it to work in every case, we have to check for both possibilities:
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));
}
}
精彩评论