Open a document (iOS)

You have a few options to open a document such as with a document view controller or tabbed document view controller.

PTPDFViewCtrl in Xamarin.iOS

This tutorial only applies to Xamarin.iOS. See Xamarin.Android equivalent here .

Displaying a PDF

The easiest way to display a PDF is using a PTDocumentController. The PTPDFViewCtrl is a low-level control that may be used when a higher level of customization is required.

About PTPDFViewCtrl

The PTPDFViewCtrl is a UIView that displays a PDF.

If your app is displaying a PDF, a PTPDFViewCtrl will be used in one of two ways:

  • Directly, by adding it as a subview to another view in your app.
  • As a component piece of a PTDocumentController or PTTabbedDocumentViewController. (It is accessible via the pdfViewCtrl property.)

Use PTPDFViewCtrl as a stand-alone component

  1. These instructions assume that you've initialized Apryse.
  2. 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
  3. Instantiate a new PDFDoc:

C#

1var pdfPath = "sample.pdf";
2var docToOpen = new pdftron.PDF.PDFDoc(pdfPath);
  1. Create a new PDFViewCtrl and add it as a child to the current view:Running the app will now display the PDF sample.pdf. However, it will not support annotation creation, editing, text selection, or any other UI aspect that is handled by Tools package . To add support for annotations and text selection you need to incorporate the tools package .

C#

1// Create a new PDFViewCtrl
2var pdfViewCtrl = new pdftron.PDF.PDFViewCtrl();
3
4// Set the document to display
5pdfViewCtrl.Doc = TypeConvertHelper.ConvPDFDocToNative(docToOpen);
6
7// Add the PDFViewCtrl to the current view controller's root view.
8View.AddSubview(pdfViewCtrl);
9
10// Auto Layout
11pdfViewCtrl.TranslatesAutoresizingMaskIntoConstraints = false;
12NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] {
13 pdfViewCtrl.LeadingAnchor.ConstraintEqualTo(this.View.LeadingAnchor),
14 pdfViewCtrl.WidthAnchor.ConstraintEqualTo(this.View.WidthAnchor),
15 pdfViewCtrl.TopAnchor.ConstraintEqualTo(this.View.LayoutMarginsGuide.TopAnchor),
16 pdfViewCtrl.BottomAnchor.ConstraintEqualTo(this.View.BottomAnchor)
17});

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales