Some test text!

menu
search
Add a license keykeyboard_arrow_down

Add license key

This guide demonstrates how to initialize PDFNet with a license key. To begin working with PDFNet, you must have first added it to your project.

  1. Import PDFNet.

    If you have not already done so, import PDFNet to make it accessible.

    Import PDFNet

    Importing PDFNet. The equivalent in Objective-C is #import.
  2. PDFNet must be initialized before any other PDFNet API calls are made. This only needs to be done once. If you have a commercial license key, it must be passed in to the initialize method. (An invalid key will result in the library running in demo mode.) Initializing PDFNet is done as shown:

    Your license key is confidential. Please make sure that it is not publicly available (e.g. in your public GitHub).
    PTPDFNet.initialize("Insert commercial license key here after purchase")

    If there was a problem with the initialization, the call will throw an error (exception in Obj-C).

linkInitializing PDFNet in a Swift project that uses storyboards

The app lifecycle in a Swift project that uses storyboards is different than other iOS projects, they require careful handling to ensure PDFNet is initialized before its classes are used.

In Swift projects that use storyboards, non-optional stored properties that are instantiated at the point of declaration are instantiated before most code has a chance to run, including application(_:willFinishLaunchingWithOptions:). This means that even if you initialize PDFNet with a license key in this method, which is "your app’s first chance to execute code at launch time", it will result in an error.

To initialize PDFNet beforeapplication(_:willFinishLaunchingWithOptions:), add a new property in AppDelegate.swift that is initialized with the result of a call to PDFNet's initialize method (which is void):

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    private let pdfnetInitialize = PTPDFNet.initialize("Insert commercial license key here after purchase")

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

Alternatively, non-optional stored properties could be instantiated in the class's init functions, in which case application(_:willFinishLaunchingWithOptions:) will be run first.

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.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn More
close