【问题标题】:How to get image from FileAttachment Annotation in pdf file如何从pdf文件中的FileAttachment Annotation获取图像
【发布时间】:2013-09-05 15:24:19
【问题描述】:

我正在开发 PDF 注释应用程序我在 iPhone 中添加了 PDF 文件注释它工作正常它的注释也可见任何阅读器但面临一个问题如何从 PDF 文件中的文件附件注释获取图像,其是从桌面创建的注释如何做对于这个问题

我正在使用此代码从文件附件注释中获取注释的内容和位置,它工作正常

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));

更新

    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;
   }

请帮帮我

提前谢谢你

【问题讨论】:

    标签: iphone ios objective-c pdf


    【解决方案1】:

    终于得到解决方案

    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];
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-11
      • 1970-01-01
      • 1970-01-01
      • 2016-04-04
      • 1970-01-01
      • 2010-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多