问题描述
我有一个带有PDF查看器的应用程序,我尝试使用需要PDFKit.PDFDocument
对象的PDFKit.PDFView
.
I have an application with PDF viewer, and I try to use PDFKit.PDFView
which need to PDFKit.PDFDocument
object.
我的代码是:
var pdfview = new PdfKit.PdfView();
var path = NSBundle.MainBundle.PathForResource("Harvard", "pdf");
var urll = new NSUrl(path);
var pdfdoc = new PdfDocument(urll);
pdfview.Document = pdfdoc;
第4行出现异常:
我的pdf文件Harvard.pdf处于Resources文件夹中,并通过BundleResource构建动作位于直接的iOS项目目录中.
My pdf file, Harvard.pdf, is in Resources folder and in direct iOS project directory with BundleResource build action.
使用CGPDFDocument
可以轻松阅读此PDF文件,但是我需要使用PDFView
解决我之前提出的问题处理在iOS上的PDF查看器中快速单击的链接一个>.所以,有人可以帮我吗?
this PDF file can be read easily with CGPDFDocument
, but I need to use PDFView
to solve problem I asked for it before in handle links clicking inside PDF viewer on iOS with swift.So, can anyone help me please?
推荐答案
尝试以下方法检查URL
是否返回nil
:
Have a try with follow way to check whether URL
return nil
:
var documentURL = NSBundle.MainBundle.GetUrlForResource("Harvard", "pdf");
var pdfdoc = new PdfDocument(documentURL);
这是完整的示例代码:
var documentURL = NSBundle.MainBundle.GetUrlForResource("MyForm", "pdf");
if (documentURL != null)
{
var document = new PdfDocument(documentURL);
//var page = document.GetPage(0);
var pdfview = new PdfKit.PdfView();
pdfview.Frame = View.Frame;
pdfview.Document = document;
pdfview.AutoScales = true;
pdfview.UserInteractionEnabled = true;
pdfview.BackgroundColor = UIColor.Gray;
View.AddSubview(pdfview);
}
效果:
这篇关于在iOS上使用PDFKit.PDFView打开PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!