如何从pdf文件中的FileAttachment Annotation获取图像 [英] How to get image from FileAttachment Annotation in pdf file

查看:194
本文介绍了如何从pdf文件中的FileAttachment Annotation获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究PDF注释应用程序我在iPhone中添加PDF文件注释它工作正常它注释也可见任何读者但面临一个问题如何从PDF文件中获取图像文件从桌面创建注释如何才能做到对于这个问题

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

更新

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

请帮帮我

提前谢谢

推荐答案

最终获得解决方案

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

这篇关于如何从pdf文件中的FileAttachment Annotation获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆