2012-04-17 6 views
2

私はしばらくの間、PDFパッケージに含まれているpdfドキュメントを解凍できるように努力してきました。どこにもドキュメンテーションやサンプルコードは見つかりませんでしたが、Adobe ReaderアプリとPDFExpertアプリでサポートされているため不可能ではありません。私がそれはそれに付属していません願って、彼らは自分のパーサを持っている可能性があり...PDF iOSのパッケージ

正しい方向に私を指すようになります任意のヒントを大幅に

編集を理解されるであろう。長い時間の後私はこれに取り組んで、ついにそれを理解しました。 正しい方向に私を向けるiPDFDevに特別なおかげで!

ここで、各インナーCGPDFDocumentRef取得する方法上のコードです:私はあなたがPDFポートフォリオを参照してくださいと仮定PDFパッケージで

NSURL *url = [NSURL fileURLWithPath:filePath isDirectory:NO]; 
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((__bridge CFURLRef)url); 
CGPDFDictionaryRef catalog = CGPDFDocumentGetCatalog(pdf); 

CGPDFDictionaryRef names = NULL; 
if (CGPDFDictionaryGetDictionary(catalog, "Names", &names)) { 
    CGPDFDictionaryRef embFiles = NULL; 
    if (CGPDFDictionaryGetDictionary(names, "EmbeddedFiles", &embFiles)) { 
     // At this point you know this is a Package/Portfolio 

     CGPDFArrayRef nameArray = NULL; 
     CGPDFDictionaryGetArray(embFiles, "Names", &nameArray); 

     // nameArray contains the inner documents 
     // it brings the name and then a dictionary from where you can extract the pdf 

     for (int i = 0; i < CGPDFArrayGetCount(nameArray); i+=2) { 
      CGPDFStringRef name = NULL; 
      CGPDFDictionaryRef dict = NULL; 

      if (CGPDFArrayGetString(nameArray, i, &name) && 
       CGPDFArrayGetDictionary(nameArray, i+1, &dict)) { 
       NSString *_name = [self convertPDFString:name]; 

       CGPDFDictionaryRef EF; 
       if (CGPDFDictionaryGetDictionary(dict, "EF", &EF)) { 
        CGPDFStreamRef F; 
        if (CGPDFDictionaryGetStream(EF, "F", &F)) { 
         CFDataRef data = CGPDFStreamCopyData(F, NULL); 
         CGDataProviderRef provider = CGDataProviderCreateWithCFData(data); 

         CGPDFDocumentRef _doc = CGPDFDocumentCreateWithProvider(provider); 
         if (_doc) { 
          // save the docRef somewhere (_doc) 
          // save the pdf name somewhere (_name) 
         } 

         CFRelease(data); 
         CGDataProviderRelease(provider); 
        } 
       } 
      } 
     } 
    } 
} 



- (NSString *)convertPDFString:(CGPDFStringRef)string { 
    CFStringRef cfString = CGPDFStringCopyTextString(string); 
    NSString *result = [[NSString alloc] initWithString:(__bridge NSString *)cfString]; 
    CFRelease(cfString); 
    return result; 
} 
+0

これまでに動作させましたか?私はあまりにも苦労しています... – JMIT

+0

ええ、それは私が使用したコードです。私はCGPDF APIがまだ動作していると仮定します – Ismael

答えて

1

が。 PDFポートフォリオのファイルは基本的にいくつかの拡張属性を持つドキュメント添付ファイルで、EmbeddedFilesツリーにあります。ドキュメントカタログ辞書から始めます。ドキュメントカタログ辞書から、/ Names辞書を取得します。/Namesディクショナリから、存在する場合(オプション)、/ EmbeddedFilesディクショナリを取得します。存在する場合は、埋め込みファイルツリーの先頭を表します(PDF仕様の名前ツリー)。
PDF仕様(ここではhttp://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdfで利用可能)は、セクション7.9.6で名前ツリーを記述し、ツリーの解析方法を理解します。
このツリーは、文字列識別子をファイル指定辞書(7.11.3項)にマップします。ファイル指定辞書から、埋め込みファイルストリームである/ EFキーの値を取得します(7.11.4節)。このオブジェクトに関連付けられたストリームは、探しているファイルコンテンツです。

関連する問題