Initializing Nutrient
Apps using Nutrient need to initialize the framework before its first use. This can be done either automatically at application startup, or manually. Before initializing Nutrient, be sure to acquire a valid license key.
Automatic initialization
The easiest way to initialize Nutrient 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, Nutrient 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, Nutrient will initialize the SDK in trial mode.
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 Nutrient 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, Nutrient won’t initialize itself at startup. Instead, use the PSPDFKit.initialize()
method, which takes an [InitializationOptions
][] object:
PSPDFKit.initialize( context, InitializationOptions( licenseKey = "YOUR_LICENSE_KEY_GOES_HERE", // ... Add other possible options 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.