是因为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. 是否有可能在iOS
- 6. 是否有可能从Windows PC访问IOS设备没有iTunes
- 7. 是否可以为LaTeX开发功能?
- 8. 是否有可能通过应用限制iOS访问?
- 9. 是否有可能访问iphone笔记,IOS中的日历?
- 10. 是否有可能在平展PDF
- 11. 是否有可能在Ghostscript的以PDF
- 12. 是否有可能为iOS编译potrace?
- 13. 是否有可能在打开websocket连接时发送数据
- 14. 使用iOS,是否有可能检测iPhone何时开启?
- 15. 是否有PDF库可以处理可访问性?
- 16. 是否有可能触发在Chrome中打开一个PDF与下载它
- 17. 是否有可能开发为iOS应用程序的转弯导航?
- 18. 获取PDF文档大纲
- 19. 是否可以在Ubuntu下为ios开发设置cordova?
- 20. 是否有可能为SharePoint 2010开发WP7应用程序?
- 21. 是否有可能将图像转换为PDF在android中
- 22. PDF/A-1b +可访问性是否等于PDF/A-1a?
- 23. 专为iOS 6开发是否安全?
- 24. iOS中是否有开启功能?
- 25. 是否可以在大纲示例中使用表格数据?
- 26. chrome.storage.sync.set - 开发者是否可以访问这些数据?
- 27. 是否有可能在触发
- 28. java - 是否有可能在PC上开发GPS软件
- 29. 是否有可能在C++中开发静态循环?
- 30. 是否有可能在rebol中开发ssh协议?