是因爲PDFKit在iOS上不可用,如何才能在該環境中獲得pdf文檔的大綱?像FastPdfKit或PSPDFKit這樣的商業圖書館是唯一的解決方案嗎?是否有可能在爲iOS開發時訪問pdf大綱
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(如果沒有)。
相關問題
- 1. 是否有功能大綱?
- 2. 是否有可能訪問
- 3. 是否仍有可能爲較老的iOS設備開發?
- 4. 是否有可能在iOS中訪問系統鑰匙串?
- 5. 是否有可能訪問iphone筆記,IOS中的日曆?
- 6. 是否有可能通過應用限制iOS訪問?
- 7. 是否可以爲LaTeX開發功能?
- 8. 是否有可能在平展PDF
- 9. 使用iOS,是否有可能檢測iPhone何時開啓?
- 10. 獲取PDF文檔大綱
- 11. 是否可以在Ubuntu下爲ios開發設置cordova?
- 12. 是否有可能爲SharePoint 2010開發WP7應用程序?
- 13. PDF/A-1b +可訪問性是否等於PDF/A-1a?
- 14. iOS中是否有開啓功能?
- 15. 是否有可能在觸發
- 16. chrome.storage.sync.set - 開發者是否可以訪問這些數據?
- 17. iOS:是否可以爲側裝開發應用推送更新?
- 18. 是否有可能在rebol中開發ssh協議?
- 19. 是否有可能在eclipse中進行iPhone開發?
- 20. Salesforce:是否有可能在Salesforce上開發Web應用程序
- 21. java - 是否有可能在PC上開發GPS軟件
- 22. 是否有可能在.NET中捕獲訪問衝突異常?
- 23. 是否有可能在JavaScript中捕獲財產訪問權限?
- 24. 是否可以開發具有藍牙功能的iOS應用程序?
- 25. 是否有可能禁用iOS上
- 26. 如何獲取iOS(iPad)中的PDF目錄(大綱)數據?
- 27. 是否有可能有一個自定義.gitignore?只讀訪問?
- 28. IOS - 文件添加觸發事件 - 是否有可能
- 29. 是否有可能在android中訪問運行時解密文件?
- 30. 訪問VBA:Access DB打開時是否可以執行VBA代碼?