我正在尝试将 PDF 文件打开到我的应用程序中,并在 UINavigationBar
中使用自定义 UIBarButtonItem
,有两个选项可将 pdf 打开到 IOS
-UIDocumentInteractionController
-QLPreviewController
在IOS6
中,我发现这篇文章证明我们无法自定义UINavigationBar
Custom navigationItem button with QLPreviewController in iOS6
QLPreviewController remove or add UIBarButtonItems
http://www.cimgf.com/2012/07/11/a-better-fullscreen-asset-viewer-with-quicklook/
Custom "Email" action in UIDocumentInteractionController
“iOS6
更新 这种覆盖QLPreviewController
的技术在iOS 6
中将不再起作用。我已经就这种情况联系了Apple,但是他们只是表示不再支持它,并且它被视为私有(private) API”
是否有其他方法可以在不使用 UIWebView
的情况下在 IOS
中打开 PDF 并自定义 UIBarButtonItem
。
最佳答案
我不知道您到底想对 PDF 做什么,但您可以使用如下代码从 bundle 中打开 PDF 文件:
CGPDFDocumentRef pdfDoc;
CGPDFPageRef pdfPage;
NSURL* pdfURL = [[NSBundle mainBundle] URLForResource:@"filename" withExtension:@"pdf"];
CFURLRef urlRef = (__bridge CFURLRef)pdfURL;
pdfDoc = CGPDFDocumentCreateWithURL(urlRef);
if (pdfDoc == NULL) {
// Not good
}
if (CGPDFDocumentIsEncrypted (pdfDoc)) {
if (!CGPDFDocumentUnlockWithPassword (pdfDoc, "")) {
if (!CGPDFDocumentUnlockWithPassword (pdfDoc, "password")) {
// Not good, document is locked
}
}
}
if (!CGPDFDocumentIsUnlocked (pdfDoc)) {
CGPDFDocumentRelease(pdfDoc);
} else {
pdfPage = CGPDFDocumentGetPage(pdfDoc, 1);
CGPDFPageRetain(pdfPage);
// ...
}
从现在起,Apple 的文档应该可以帮助您:
关于iOS打开PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17614866/