PDFKit을 iOS에서 사용할 수 없다면 pdf 개요에 액세스 할 수 있습니까? 해당 환경에서 PDF 문서의 개요를 얻는 방법은 무엇입니까? FastPdfKit 또는 PSPDFKit과 같은 상용 라이브러리가 유일한 솔루션입니까?iOS 용으로 개발할 때
0
A
답변
3
PDF 개요에 액세스하는 것이 너무 까다로운 것은 아닙니다. 내 outline parser에는 약 420 LOC가 있습니다. 일부 발췌 문장을 올리므로 아이디어를 얻을 수 있습니다. 상업용 라이브러리이므로 전체 코드를 게시 할 수 없습니다.
당신은 기본적으로 다음과 같이 시작합니다
CGPDFDictionaryRef outlineRef;
if(CGPDFDictionaryGetDictionary(pdfDocDictionary, "Outlines", &outlineRef)) {
이
NSArray *outlineElements = nil;
CGPDFDictionaryRef firstEntry;
if (CGPDFDictionaryGetDictionary(outlineRef, "First", &firstEntry)) {
NSMutableArray *pageCache = [NSMutableArray arrayWithCapacity:CGPDFDocumentGetNumberOfPages(documentRef)];
outlineElements = [self parseOutlineElements:firstEntry level:0 error:&error documentRef:documentRef cache:pageCache];
}else {
PSPDFLogWarning(@"Error while parsing outline. First entry not found!");
}
에 추락 당신은 다음과 같이 단일 항목을 구문 분석 :
// parse title
NSString *outlineTitle = stringFromCGPDFDictionary(outlineElementRef, @"Title");
PSPDFLogVerbose(@"outline title: %@", outlineTitle);
if (!outlineTitle) {
if (error_) {
*error_ = [NSError errorWithDomain:kPSPDFOutlineParserErrorDomain code:1 userInfo:nil];
}
return nil;
}
NSString *namedDestination = nil;
CGPDFObjectRef destinationRef;
if (CGPDFDictionaryGetObject(outlineElementRef, "Dest", &destinationRef)) {
CGPDFObjectType destinationType = CGPDFObjectGetType(destinationRef);
가장 짜증나는 것은 당신이 Named Destinations을 가지고있다 대부분의 PDF 문서에서는 해결할 추가 단계가 필요합니다. 배열에 저장하고 나중에 해결합니다.
PDF의 차이점이 많이 있기 때문에 "제대로 처리"하는 데는 상당한 시간이 걸렸으며 PDF 참조를 준수하는 모든 내용을 구현하더라도 적용 할 때까지 일부 파일이 작동하지 않습니다. 추가 조정. (PDF는 엉망입니다!)
0
이제 iOS 11 이상 버전에서 가능합니다.
https://developer.apple.com/documentation/pdfkit
당신은 PDFDocument의 PDFOutline를 얻을 수 있습니다. PDFOutline의 outlineRoot는 아웃 라인 항목이 있으면 반환하고 아무 것도 없으면 NULL을 반환합니다.