Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

iphone - How to get image from FileAttachment Annotation in pdf file

i am working on PDF annotation app i added PDF file annotation in iPhone it working fine it annotation also visible any reader but facing one issue How to get image from File Attachment Annotation in PDF file whose is created annotation from desktop how can do for this issue

i am using this code for get contents and location of annotation from File Attachment Annotation it working fine

CGPDFDictionaryRef pageDictionary = CGPDFPageGetDictionary(pPage);
  //  NSLog(@"%@",(NSDictionary*)pageDictionary);
    CGPDFArrayRef outputArray;
    if(!CGPDFDictionaryGetArray(pageDictionary, "Annots", &outputArray)) {
        [pdfAnnots release];
        return nil;
    }
 CGPDFArrayRef rectArray;
            if(!CGPDFDictionaryGetArray(annotDict, "Rect", &rectArray)) {
                break;
            }

            int arrayCount = CGPDFArrayGetCount( rectArray );
            CGPDFReal coords[4];
            for( int k = 0; k < arrayCount; ++k ) {
                CGPDFObjectRef rectObj;
                if(!CGPDFArrayGetObject(rectArray, k, &rectObj)) {
                    break;
                }

                CGPDFReal coord;
                if(!CGPDFObjectGetValue(rectObj, kCGPDFObjectTypeReal, &coord)) {
                    break;
                }

                coords[k] = coord;
            }               

            CGRect rect = CGRectMake(coords[0],coords[1],coords[2],coords[3]);

            NSLog(@"%@",NSStringFromCGRect(rect));

Update

    CGPDFDictionaryRef aDict;

    if(CGPDFDictionaryGetDictionary(annotDict, "AP", &aDict)) 
    {

      CGPDFStreamRef textStringRef33;
        if(CGPDFDictionaryGetStream(aDict, "N", &textStringRef33)) {


         UIImage *image= getImageRef(textStringRef33);
            CGPDFDataFormat *format = NULL;

            CFDataRef contdata = CGPDFStreamCopyData( textStringRef33, format );

            NSData *data=(NSData*)contdata;
   }

please help me

Thank you in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

finally get solution

CGPDFDictionaryRef aDict;
    NSData *imagedata=nil;
    if(CGPDFDictionaryGetDictionary(annotDict, "FS", &aDict))
    {
        CGPDFDictionaryRef embeddedFiles;
        if (CGPDFDictionaryGetDictionary (aDict, "EF", &embeddedFiles) )
        {

            CGPDFStreamRef streamDict;
            if (CGPDFDictionaryGetStream(embeddedFiles, "F", &streamDict))
            {
                CGPDFDataFormat *format = NULL;
                CFDataRef xmlData;

                xmlData = CGPDFStreamCopyData (streamDict, format);
                imagedata=(NSData*)xmlData;

                  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                  NSString *documentsDirectory = [paths objectAtIndex:0];
               savedImagePath = [documentsDirectory stringByAppendingPathComponent:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
               [(NSData*)xmlData writeToFile:savedImagePath atomically:NO];
            }
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...