我正在尝试使用新的 iOS 11 框架 pdfkit 打开 PDF 文件。
但我无法做到这一点。
所以帮助我使用 pdfkit 框架打开文件。
先感谢您。
这是基于 Objective-C 的示例
Ensure PDFKit framework is added to the project
导入框架头#import <PDFKit/PDFKit.h>
-
创建 PDFDocument 实例。就我而言,它使用 NSURL
// fileURL is NSURL file path instance created using base64 pdf content
PDFDocument *pdfDocument = [[PDFDocument alloc] initWithURL:fileURL];
-
创建 PDFView 实例并将 pdfDocument 文档分配给它
PDFView *pdfView = [[PDFView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
pdfView.document = pdfDocument;
pdfView.displayMode = kPDFDisplaySinglePageContinuous;
pdfView.autoScales = true;
pdfView.layer.borderWidth = 2;
pdfView.layer.borderColor = [UIColor blueColor].CGColor;
正如许多其他人所做的那样,我们使用 webview 来显示 PDF 内容并与之交互。通读框架并尝试一些示例,PDFKit 是一个深思熟虑的设计,其中有大量开箱即用的功能,并且简化了开发。
例如,我们在应用程序中具有 AirPrint 功能,该功能具有此检查以确定可打印性
if ([UIPrintInteractionController canPrintData: fileData]) {
用 PDFKit 替换 webview 实现后,我只需要使用dataRepresentation
获取 fileData 的方法,其余部分按原样工作
NSData *fileData = [pdfDocument dataRepresentation];
请检查此 WWDC 页面 https://developer.apple.com/videos/play/wwdc2017/241/了解更多详情
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)