Some test text!

platform
search

PTPDFViewCtrl

Contents

About PTPDFViewCtrl
Using PTPDFViewCtrl as a Stand-Alone Component
Customize a PTPDFViewCtrl
Properties and Methods
Delegate Callbacks
This tutorial only applies to Xamarin.iOS.
Displaying a PDF
The easiest way to display a PDF is using a PTDocumentViewController. The PTPDFViewCtrl is a low-level control that may be used when a higher level of customization is required.

linkAbout 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 PTDocumentViewController or PTTabbedDocumentViewController. (It is accessible via the pdfViewCtrl property.)

linkUsing PTPDFViewCtrl as a Stand-Alone Component

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

    var pdfPath = "sample.pdf";
    var docToOpen = new pdftron.PDF.PDFDoc(pdfPath);
  2. Create a new PDFViewCtrl and add it as a child to the current view:

    // Create a new PDFViewCtrl
    var pdfViewCtrl = new pdftron.PDF.PDFViewCtrl();
    
    // Set the document to display
    pdfViewCtrl.Doc = TypeConvertHelper.ConvPDFDocToNative(docToOpen);
    
    // Add the PDFViewCtrl to the current view controller's root view.
    View.AddSubview(pdfViewCtrl);
    
    // Auto Layout
    pdfViewCtrl.TranslatesAutoresizingMaskIntoConstraints = false;
    NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] {
        pdfViewCtrl.LeadingAnchor.ConstraintEqualTo(this.View.LeadingAnchor),
        pdfViewCtrl.WidthAnchor.ConstraintEqualTo(this.View.WidthAnchor),
        pdfViewCtrl.TopAnchor.ConstraintEqualTo(this.View.LayoutMarginsGuide.TopAnchor),
        pdfViewCtrl.BottomAnchor.ConstraintEqualTo(this.View.BottomAnchor)
    });

    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.

linkCustomize a PTPDFViewCtrl

The PDFViewCtrl has a large API that can be used to control how the PDF is presented to the user. All of the APIs that you can use are well documented. This guide highlights some of the most commonly used functionality.

If you are using a PTDocumentViewController (or PTTabbedDocumentViewController), the contained PTPDFViewCtrl can be accessed as a property:

var documentViewController = new pdftron.PDF.Controls.PTDocumentViewController();

documentViewController.pdfViewCtrl

linkProperties and Methods

APIDescription
SetPagePresentationModeSet how pages are presented and scrolled: in 1 or 2 columns, scrolled vertically or horizontally
SetPageViewModeSets the zoom level relative to the page size, fit-width, fit-height or fit-page.
SetPageRefViewModeWhen a document is scrolled via horizontal swipes, use this method to control what zoom level new pages are rendered at.
SetBackgroundColorSets the color that is seen around pages.
SetupThumbnailsControls how low-resolution thumbnails are handled. Enlarged thumbnails are used in place of high-resolution content while the high-resolution content is being rendered.
overlayViewThis view is used for drawing system-content over the PDF.
SetProgressiveRenderingControls how frequently the high-resolution content is updated while it is being rendered.
SetDrawAnnotationsControls if annotations are visible.
SetHighlightFieldsControls if form fields are shaded with light blue.
SetOverprintControls how PDFs that use overprint colors are rendered.
SetColorPostProcessModeCan be used to turn on night-mode and other color processing changes.

linkDelegate Callbacks

The PDFViewCtrl includes two delegates (delegate and toolDelegate) to relay touch and other events that occur on the control.

The first is a general purpose delegate, the second was designed specifically for enabling the Tools.framework functionality via its conforming object PTToolManager. If you are using the tools framework, a PTToolManager should always be assigned as the PTPDFViewCtrl's toolDelegate object. If you are not using the Tools.framework, it may be used for whatever purpose your app requires.

Delegates when using a PTDocumentViewController
When using a PTDocumentViewController (or PTTabbedDocumentViewController), the PTPDFViewCtrl delegates are used internally and cannot be reassigned to another object. To receive the delegate callbacks, create a subclass of PTDocumentViewController and implement the required methods, being sure to call super.

Get the anwsers you need: Support

Contents

About PTPDFViewCtrl
Using PTPDFViewCtrl as a Stand-Alone Component
Customize a PTPDFViewCtrl
Properties and Methods
Delegate Callbacks