Frequently Asked Question

Annotation Properties (iOS)
Last Updated 11 months ago

If you have a premium license, you can use the advanced properties to get some informations about the annotation, like the creation date, modification date...etc.

To use the advanced properties, you can create a class to manage the annotation like the following, and call checkAnnotAdvancedProp:

Header file:

#import 
#import "PDFObjc.h"
@interface RDAdvancedProperties : NSObject
@property (strong, nonatomic) PDFDoc *doc;
- (NSString *)getTypeName:(int)type;
- (void)checkAnnotAdvancedProp:(PDFAnnot *)annot;
- (void)handleRef:(PDF_OBJ_REF)ref;
- (void)handleDictionary:(PDFObj *)obj;
@end

Source file:

#import "RDAdvancedProperties.h"
@implementation RDAdvancedProperties {
    NSArray *types;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        //define advanced properties types
        types = @[@"null", @"boolean", @"int", @"real", @"string", @"name", @"array", @"dictionary", @"reference", @"stream"];
    }
    return self;
}

- (NSString *)getTypeName:(int)type
{
    if (type >= 0 && type < types.count) {
        return [types objectAtIndex:type];
    }    
    return @"unknown";
}

- (void)checkAnnotAdvancedProp:(PDFAnnot *)annot
{
    if (annot == nil) {
        return;
    }
    [self handleRef:[annot advanceGetRef]];
}

- (void)handleRef:(PDF_OBJ_REF)ref
{
    if (ref) {
        PDFObj *obj = [_doc advanceGetObj:ref];
        [self handleDictionary:obj];   
}

- (void)handleDictionary:(PDFObj *)obj
{
    int count = obj.dictGetItemCount;
    for (int cur = 0; cur < count; cur++) {
        NSString *tag = [obj dictGetItemTag:cur];
        PDFObj *item = [obj dictGetItemByIndex:cur];
        int type = item.getType;
        NSString *typeName = [self getTypeName:type];        

        NSLog(@"--ADV-- tag: %i --- %@:%@ ->", cur, tag, typeName);

        switch (type) {
            case 1: //boolean
                NSLog(@"--ADV-- value = %i", item.getBoolVal);
                break;
            case 2: //int
                NSLog(@"--ADV-- value = %i", item.getIntVal);
                break;
            case 3: //float
                NSLog(@"--ADV-- value = %f", item.getRealVal);
                break;
            case 4: //string
                NSLog(@"--ADV-- value = %@", item.getTextStringVal);
                break;
            case 5: //name
                NSLog(@"--ADV-- value = %@", item.getNameVal);
                break;            case 6: //array
            {
                int arrayCount = item.arrayGetItemCount;
                for (int k = 0; k < arrayCount; k++) {
                    PDFObj *array_obj = [item arrayGetItem:k];
                    NSLog(@"--ADV-- array item %i: value = %f", k, array_obj.getRealVal);
                }            
                break;
            }
            case 7: //dictionary
                [self handleDictionary:item];
                break;
                default:
                break;
        }
    }
}
@end 

To use the RDAdvancedProperties class in your PDFView instance, you can do the following:

    RDAdvancedProperties *adv = [RDAdvancedProperties new];
    adv.doc = m_doc;
    [adv checkAnnotAdvancedProp:m_annot];

Loading ...