iOS打开PDF

标签 ios

我正在尝试将 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 的文档应该可以帮助您:

Quartz 2D Programming Guide

Core Graphics Framework Reference

关于iOS打开PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17614866/

相关文章:

ios - 遍历 TableViewCells 会跳过一些

iphone - 刚刚发布到 AppStore 的应用程序在 iOS 3.0 不全面的存档上崩溃

ios - 来自另一个类的变量

ios - Stripe - STPPaymentCardTextField - 如何删除或隐藏 CVC 代码字段?

ios - iOS-如何处理文件名中的空格

ios - 使用 AVFoundation 裁剪 AVAsset 视频

ios - Facebook 权限 - com.apple.accounts 错误 8

ios - 初始化中隐式解包的可选值 - Swift

iphone - 我必须使用哪些 iOS 设备进行测试?

ios - 如何将触摸 socket 添加到自定义 UIView?