2010-03-31 25 views
5

gelen içindekiler tablosu oluşturun ve ben pdf gezinmek için bir içindekiler tablosu oluşturmak gerekir. Apple'ın belgelerine okuyunca ben CGPDFDocumentGetCatalog kullanmak gerekiyor düşünüyorum, ama bu her yerde nasıl kullanılacağına ilişkin herhangi bir örnek bulamıyorum. Herhangi bir fikir?Ben pdf içeriği görüntülemek için kuvars kullanıyorum pdf dosyası

Güncelleme: Hala bunun için bir çözüm bulamadı. Yorgunum Alex'in' çözüm ama olsun çıktı şuna benzer:

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 

Fikrim yok henüz içindekiler kullanılabilir bir tabloya o nasıl açacağınızı. İdeal olarak, bir başlık ve eşleşen sayfa numarası olan NSDictionary nesnesine ulaşmak istiyorum. Böyle

+0

Ryan, PDF varolan gelen TOC oluşturmak için herhangi bir yol buldu yaptı? Eğer öyleyse lütfen bana yol göster. Birkaç gündür aynı şeyi arıyorum. – DivineDesert

+0

Herhangi bir çözüm buldunuz mu? Cevabınız evet ise lütfen cevabınızı buraya ekleyin. – Hemang

cevap

6

şey başlamanıza yardımcı olabilir:

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 
    }  
} 
+0

'CGPDFDocumentApplyFunction' nerede tanımlandığı? –

+1

Üzgünüz, bu 'CGPDFDictionaryApplyFunction' olmalıdır. 'CoreGraphics.framework'daki 'CGPDFDictionary.h' başlık dosyasına bakın. Yakalama için teşekkürler. –

+0

Merhaba @AlexReynolds, siz de Swift 3 Cevabınızı dönüştürebilirsiniz? – Hemang

4

için ücretsiz bir kütüphane ile did it İşte benim yaklaşımdır.
1. Scarica çerçeve vfr reader
2. Bu kod satırlarını tüm PDF bölümleri

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

almak için size yardımcı olacaktır Umut.

+0

Vfr okuyucu ve bu snippet'i kullanarak benim için mükemmel bir şekilde çalıştı. Çok kullanışlı. – AndyDunn

İlgili konular