6

私はクォーツを使用してpdfコンテンツを表示しています.pdfをナビゲートするために目次を作成する必要があります。Apple のドキュメントを読むと、CGPDFDocumentGetCatalog を使用することになっていると思いますが、これを使用する方法の例はどこにも見つかりません。何か案は?

更新:これに対する解決策はまだ見つかっていません。私はアレックスのソリューションに飽きましたが、得られる出力は次のようになります。

2011-07-27 09:16:19.359 LDS Scriptures App-iPad[624:707] key: Pages
2011-07-27 09:16:19.361 LDS Scriptures App-iPad[624:707] key: Count
2011-07-27 09:16:19.362 LDS Scriptures App-iPad[624:707] pdf integer value: 238
2011-07-27 09:16:19.363 LDS Scriptures App-iPad[624:707] key: Kids
2011-07-27 09:16:19.366 LDS Scriptures App-iPad[624:707] key: Type
2011-07-27 09:16:19.368 LDS Scriptures App-iPad[624:707] key: Outlines
2011-07-27 09:16:19.370 LDS Scriptures App-iPad[624:707] key: Count
2011-07-27 09:16:19.371 LDS Scriptures App-iPad[624:707] pdf integer value: 7
2011-07-27 09:16:19.372 LDS Scriptures App-iPad[624:707] key: First
2011-07-27 09:16:19.374 LDS Scriptures App-iPad[624:707] key: Parent
2011-07-27 09:16:19.375 LDS Scriptures App-iPad[624:707] key: Count
2011-07-27 09:16:19.376 LDS Scriptures App-iPad[624:707] pdf integer value: 7

それを使用可能な目次に変える方法はまだわかりません。NSDictionary理想的には、タイトルと一致するページ番号を持つオブジェクトの配列を取得したいと考えています。

4

4 に答える 4

6

このようなものがあなたが始めるのに役立つかもしれません:

NSURL *documentURL = ...; // URL to file or http resource etc.
CGPDFDocumentRef pdfDocument = CGPDFDocumentCreateWithURL((CFURLRef)documentURL);
CGPDFDictionaryRef pdfDocDictionary = CGPDFDocumentGetCatalog(pdfDocument);
// loop through dictionary...
CGPDFDictionaryApplyFunction(pdfDocDictionary, ListDictionaryObjects, NULL);
CGPDFDocumentRelease(pdfDocument);

...

void ListDictionaryObjects (const char *key, CGPDFObjectRef object, void *info) {
    NSLog("key: %s", key);
    CGPDFObjectType type = CGPDFObjectGetType(object);
    switch (type) { 
        case kCGPDFObjectTypeDictionary: {
            CGPDFDictionaryRef objectDictionary;
            if (CGPDFObjectGetValue(object, kCGPDFObjectTypeDictionary, &objectDictionary)) {
                CGPDFDictionaryApplyFunction(objectDictionary, ListDictionaryObjects, NULL);
            }
        }
        case kCGPDFObjectTypeInteger: {
            CGPDFInteger objectInteger;
            if (CGPDFObjectGetValue(object, kCGPDFObjectTypeInteger, &objectInteger)) {
                NSLog("pdf integer value: %ld", (long int)objectInteger); 
            }
        }
        // test other object type cases here
        // cf. http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/CGPDFObject/Reference/reference.html#//apple_ref/doc/uid/TP30001117-CH3g-SW1
    }    
}
于 2010-03-31T23:36:30.503 に答える
4

これが私のアプローチです。
1. このフレームワークをダウンロードします2. このコード行を使用して、すべての PDF チャプターを取得しますvfr reader

NSString *path = [[NSBundle mainBundle] pathForResource:@"Reader" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSArray *arr = [ReaderDocumentOutline outlineFromFileURL:targetURL password:@""];

それがあなたを助けることを願っています。

于 2013-02-04T14:37:01.110 に答える
0

私はiOS用のフリーウェアライブラリでそれをやったFastPdfKit

于 2012-01-17T14:24:04.130 に答える