Using PDFViewCtrlkeyboard_arrow_down

Using PDFViewCtrl

This article only applies to Xamarin.iOS.

This guide demonstrates how to display a PDF. To begin working with PDFNet, you must have first added it to your project, and initialized the library.

  1. Add a PDF to your project:

    • Right click on Resources
    • Click on Add > Add Files
    • Choose a file (in this tutorial, let's say we added a sample.pdf) and confirm add
    • Make sure the Build Action of the file is set to BundleResource
  2. Instantiate a new PDFDoc, using the PDF that was added in step 1:

var docPath = "sample.pdf";
var mPdfdoc = new pdftron.PDF.PDFDoc(docPath);
  1. Create a new PDFViewCtrl and add it as a child to the current view:
CGRect viewRect = new CGRect(0, 0, View.Frame.Size.Width, View.Frame.Size.Height);
var mPdfViewCtrl = new pdftron.PDF.PDFViewCtrl(viewRect);
mPdfViewCtrl.Doc = TypeConvertHelper.ConvPDFDocToNative(mPdfdoc);

View.AddSubview(mPdfViewCtrl);

mPdfViewCtrl.TranslatesAutoresizingMaskIntoConstraints = false;
NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] {
    mPdfViewCtrl.LeadingAnchor.ConstraintEqualTo(this.View.LeadingAnchor),
    mPdfViewCtrl.WidthAnchor.ConstraintEqualTo(this.View.WidthAnchor),
    mPdfViewCtrl.TopAnchor.ConstraintEqualTo(this.View.LayoutMarginsGuide.TopAnchor),
    mPdfViewCtrl.BottomAnchor.ConstraintEqualTo(this.View.BottomAnchor)
});

Running the app will now show the PDF sample.pdf. However, it will not support annotation creation, editing, text selection, or any other UI aspect that is handled by the Tools package. To add support for annotations and text selection you need to incorporate the tools library.