Some test text!

menu

Mac Catalyst PDF SDK

PTDocumentViewController in Catalyst

Above: the Catalyst sample app showing the NSToolbar on the macOS window, as well as the UIMenus provided by PTDocumentViewController.

PDFTron’s Mac Catalyst PDF SDK comes with simple-to-use Objective-C and Swift APIs to bring document viewing, creating, searching, annotation, and editing capabilities to native MacOS and iOS apps.

Our goal with Mac Catalyst is for our existing iOS UI to be as close as possible to the native AppKit look and feel -- without sacrificing functionality or the convenience of using a single API for iOS and macOS. We are continuously improving the library, so stay tuned for exciting new features. Please get in touch with us.

PDFTron’s fully supported SDK is trusted by thousands of innovative startups, governments, and Fortune 500 businesses (see customers). PDFTron technology is built from the ground up and is not dependent on any external third-party open-source software.

linkWhat is Mac Catalyst

Mac Catalyst is an exciting new technology from Apple that makes it incredibly easy to build a state-of-the-art Mac app by porting an existing iOS application.

Your PDFTron SDK-based Catalyst apps can be released via the Mac App Store or by simply sharing a binary. You can also use PDFTron macOS Electron if you need a Mac app that runs on an older macOS release (prior to macOS 10.15 Catalina).

linkDownload the PDFTron SDK for Mac Catalyst

The PDFTron SDK can easily be integrated into your Catalyst apps. Please download the SDK to try it out.

The PTDocumentViewController shows a PDF viewer and annotator complete with controls such as an annotation toolbar, page layout controls, bookmarks, thumbnail viewer, etc. All of its component pieces are part of the Tools framework, and this class packages them into one easy to use view controller.

The PTDocumentViewController in our Catalyst SDK also provides a ready-made NSToolbar which provides convenient access to many of the built-in controls described above. The toolbar is available as a property on the document view controller: documentViewController.macToolbar.

linkViewing a Document in Catalyst

To show a PTDocumentViewController, override the viewDidAppear() method in your UIViewController class and then open the DocumentViewController using:

//Import the PDFNet and Tools libraries
import PDFNet
import Tools

override func viewDidAppear(_ animated: Bool) {
    // Create a PTDocumentViewController
    let documentController = PTDocumentViewController()
    // Conform to the `PTDocumentViewControllerDelegate` protocol
    documentController.delegate = self;
    // The PTDocumentViewController must be in a navigation controller before a document can be opened
    let navigationController = UINavigationController(rootViewController: documentController)
    // Open a file from URL.
    let fileURL: URL = URL(string:"https://pdftron.s3.amazonaws.com/downloads/pl/sample.pdf")!
    documentController.openDocument(with: fileURL)
    // Show navigation (and document) controller.
    self.present(navigationController, animated: true, completion: nil)
}

To show the PTDocumentViewController's NSToolbar, make the view controller conform to the PTDocumentViewControllerDelegate protocol and implement the delegate method, documentViewControllerDidOpenDocument:documentViewController.

// Set the toolbar in the `documentViewControllerDidOpenDocument:documentViewController` delegate method
func documentViewControllerDidOpenDocument(_ documentViewController: PTDocumentViewController) {
    #if targetEnvironment(macCatalyst)
    if let window = UIApplication.shared.windows.first,
       let windowScene = window.windowScene {
            if let titlebar = windowScene.titlebar {
                let toolbar = documentViewController.macToolbar
                titlebar.toolbar = toolbar
            }
        }
    #endif
}

In addition, the view controller also provides a set of UIMenus which you can use to provide quick access to certain actions and view modes in the menu bar of your Catalyst app. To use these menus in your app you can use these menus in the buildMenuWithBuilder: method in your AppDelegate. See this guide from Apple for more information about the UIMenuSystem.

The `AppDelegate` will need a reference to an instance of the `PTDocumentViewController` class to use its menus.
override func buildMenu(with builder: UIMenuBuilder) {
     super.buildMenu(with: builder)
     
     // Make sure the App Delegate has a valid reference to a `PTDocumentViewController` object
     if documentViewController == nil {
         return
     }
     /** The View Modes menu contains actions for setting the view mode on the document
     *  e.g. Continuous scroll, single page mode, facing page mode.
     */
     let viewModesMenu:UIMenu = documentViewController.viewModesMenu

     // The Additional View menu contains actions for toggling reader mode or displaying the annotation toolbar
     let additionalViewMenu:UIMenu = documentViewController.additionalViewMenu

     /** The Navigation Lists menu contains actions for displaying navigation lists in the side panel:
     *  Table of Contents (document outline), Annotations list, User Bookmarks list, or the thumbnails browser.
     */
     let navigationListsMenu:UIMenu = documentViewController.navigationListsMenu

     // The Navigate Doc menu contains actions for navigating the document
     let navigateDocMenu:UIMenu = documentViewController.navigateDocMenu

     // The Annotate menu contains actions for adding annotations to the document
     let annotateMenu:UIMenu = documentViewController.annotateMenu

     guard builder.system == .main else { return }
     builder.insertChild(viewModesMenu, atStartOfMenu: .view)
     builder.insertChild(navigationListsMenu, atStartOfMenu: .view)
     builder.insertChild(additionalViewMenu, atStartOfMenu: .view)
     builder.insertSibling(annotateMenu, afterMenu: .view)
     builder.insertSibling(navigateDocMenu, afterMenu: .view)
}

linkCatalyst Sample App

The Catalyst sample app included in the download package demonstrates how to integrate the PDFTron SDK into your app. The sample can be found in the Samples directory in the SDK download.

Context Menus in Catalyst

Above: the Catalyst sample app showing the annotation context menu which is activated by right-clicking (control-clicking) or performing a two-finger tap gesture on the document.

macOS dark mode is also supported:

Light ModeDark Mode
Light ModeDark Mode
xcframework linking issue
Due to an ongoing issue in Xcode, you may need to remove the linked `PDFNet.xcframework` from the `Tools` project and add it again. Remember to set the xcframework to `Do Not Embed` after linking. This also applies when switching between iOS and macOS run targets.
remove PDFNetRe-add PDFNet
Top: Remove PDFNet from the Tools project. Bottom: Re-add PDFNet.

linkUnique Functionality

  • Direct MS Office document viewing and conversion
  • Fully customizable open source UI to improve app engagement
  • Document reflow to increase readability and accessibility on mobile
  • File streaming to view remote and complex documents faster
  • Night mode to improve viewing in low-light environments
  • And much more...

linkFile Type Support

  • PDF, PDF/A
  • DOC, DOCX, XLSX, XLS, PPTX, PPT (no MS Office licenses or software is required)
  • JPG, HEIF, BMP, TIF, PNG, SVG, EMF, GIF
  • PAGES, KEYNOTE, NUMBERS
  • RTF, TXT
  • HTML
  • XPS

linkOS Support

  • macOS Catalina (10.15+)

linkFree Trial

Get Started

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Upcoming webinar: How to add document collaboration to your app

Learn More
close