2010-03-31 9 views
5

저는 PDF 콘텐츠를 표시하기 위해 석영을 사용하고 있으며 pdf를 탐색하기 위해 목차를 만들어야합니다. Apple의 설명서를 읽으면서 CGPDFDocumentGetCatalog를 사용해야한다고 생각합니다.하지만 어디서나이 코드를 사용하는 방법에 대한 예제는 찾을 수 없습니다. 어떤 아이디어?PDF 파일에서 목차 만들기

업데이트 : 아직 해결 방법이 없습니다. 나는 피곤 알렉스 '솔루션을하지만 난 얻을 출력은 다음과 같습니다

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 개체의 배열을 얻고 싶습니다. 이 같은

+0

Ryan, 기존 PDF에서 TOC를 만드는 방법을 찾았습니까? 그렇다면 나를 안내 해주십시오. 나는 몇 일 동안 같은 것을 찾고 있습니다. – DivineDesert

+0

해결책을 찾았습니까? 대답이 '예'인 경우 여기에 답변을 추가하십시오. – Hemang

답변

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

'CGPDFDocumentApplyFunction'은 어디에 정의되어 있습니까? –

+1

죄송합니다. CGPDFDictionaryApplyFunction이어야합니다. 'CoreGraphics.framework'의'CGPDFDictionary.h' 헤더 파일을보십시오. 캐치를 가져 주셔서 감사합니다. –

+0

안녕하세요 @AlexReynolds, Swift 3에 대한 답변도 변환 할 수 있습니까? – Hemang

4

에 대한 프리웨어 라이브러리로했다 여기 내 접근 방식입니다.
1. 다운로드이 프레임 워크 vfr reader
2. 코드의 라인을 모두 PDF 장

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

를 얻을 수는 당신을 도울 것입니다 바랍니다.

+0

vfr 리더와이 스 니펫을 사용하여 완벽하게 작동했습니다. 굉장히 유용하다. – AndyDunn