Initializing PSPDFKit

Apps using PSPDFKit need to initialize the framework before its first use. This can be done either automatically at application startup or manually.

Automatic Initialization

The easiest way to initialize PSPDFKit is automatically during application startup. To configure automatic initialization, add <meta-data> elements to your app’s AndroidManifest.xml. Without any of the supported elements, PSPDFKit will initialize the SDK in trial mode.

License

<application>
	<meta-data
		android:name="pspdfkit_license_key"
		android:value="YOUR_LICENSE_KEY_GOES_HERE" />
</application>

Without the license key in the metadata, PSPDFKit will initialize the SDK in evaluation mode. Learn more about the free trial.

Custom Fonts

By default, the PDF renderer uses the installed system fonts (located in the system/fonts folder of your mobile device), but you can provide additional font paths by adding the following:

<application>
	<meta-data
		android:name="pspdfkit_font_path"
		android:value="assets/fonts/serifs;assets/fonts/sans" />
</application>

TrueType (.ttf) and OpenType fonts (.otf) are supported. Paths starting with a root folder named asset will be treated as an application asset and accessed via Android’s AssetManager. Otherwise, they’re expected to address a path relative to your application’s local storage. There’s no deep query for font files; only the ones that are directly in a given path will be considered. In case you need to specify multiple paths, you can do so by separating them with a ; as seen in the example above.

Manual Initialization

In some situations, you might want to initialize PSPDFKit manually at a later point (meaning not during app startup). This can be done by deactivating the automatic initialization in your AndroidManifest.xml:

<application>
	<meta-data
			android:name="pspdfkit_automatic_initialize"
            android:value="false" />
</application>

When doing so, PSPDFKit won’t initialize itself at startup. Instead, use the PSPDFKit.initialize() method, providing your personal license key:

PSPDFKit.initialize(context, "YOUR_LICENSE_KEY_GOES_HERE")
PSPDFKit.initialize(context, "YOUR_LICENSE_KEY_GOES_HERE");

Since initialization can take some time (due to extraction and loading of PSPDFKit’s native libraries), make sure to initialize PSPDFKit on a background thread, in order to not block your UI.