public final class

PSPDFKit

extends Object
java.lang.Object
   ↳ com.pspdfkit.PSPDFKit

Class Overview

Main PSPDFKit entry point. Use initialize(Context, String) to initialize the library if you are not using the PdfActivity or the PdfFragment (which handle initialization on their own).

Summary

Fields
public static final String VERSION String version of PSPDFKit library.
Public Methods
static boolean addAnalyticsClient(AnalyticsClient client)
Add a AnalyticsClient to receive analytics events from PSPDFKit.
static void clearCaches(Context context, boolean clearDiskCache)
Clears pageBitmap memory cache to free memory.
synchronized static void ensureInitialized()
Checks if PSPDFKit is initialized or throws PSPDFKitNotInitializedException if not.
static ApplicationPolicy getApplicationPolicy()
Returns application policy.
synchronized static void initialize(Context context, String licenseKey, ApplicationPolicy applicationPolicy)
Initializes PSPDFKit with a license key and a specific application policy.
synchronized static void initialize(Context context, String licenseKey)
Initializes PSPDFKit with a license key.
synchronized static boolean isInitialized()
Returns true if PSPDFKit is initialized and ready to use.
static boolean isLocalFileUri(Context context, Uri uri)
Checks whether or not PSPDFKit can extract a local filesystem path from the uri.
static boolean isOpenableUri(Context context, Uri uri)
PSPDFKit can only open URIs from content providers that also provide size information.
synchronized static void release(Context context)
Releases PSPDFKit library and all associated caches from memory.
static boolean removeAnalyticsClient(AnalyticsClient client)
Remove a previously added AnalyticsClient from PSPDFKit.
static void setApplicationPolicy(ApplicationPolicy applicationPolicy)
Sets application policy for the loaded library.
static void setLocalizationListener(LocalizationListener localizationListener)
Sets a new LocalizationListener to help with localizing SDK framework strings.
static void setLoggingEnabled(boolean enabled)
Enables or disables PSPDFKit logcat logs.
static void setNativeCrashDumpPath(String path)
Sets a directory into which native code minidumps will be stored for debugging of native crashes.
static void updateInternalUIContext(Context context)
Updates internal UI context and store it weakly to enable alert dialogs.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public static final String VERSION

String version of PSPDFKit library.

Public Methods

public static boolean addAnalyticsClient (AnalyticsClient client)

Add a AnalyticsClient to receive analytics events from PSPDFKit. This method will return true if the client was successfully added, or false if it was not added. Usually this happens if the client has already been added previously.

Parameters
client An AnalyticsClient to add.
Returns
  • true if the client was successfully added, otherwise false.

public static void clearCaches (Context context, boolean clearDiskCache)

Clears pageBitmap memory cache to free memory.

Parameters
context Application context.
clearDiskCache Clear disk cache as well.

public static synchronized void ensureInitialized ()

Checks if PSPDFKit is initialized or throws PSPDFKitNotInitializedException if not.

public static ApplicationPolicy getApplicationPolicy ()

Returns application policy. If not set, defaults to DefaultApplicationPolicy.

Returns
  • application policy.

public static synchronized void initialize (Context context, String licenseKey, ApplicationPolicy applicationPolicy)

Initializes PSPDFKit with a license key and a specific application policy. This must be called before any other call to methods in this class.

This method can safely be called multiple times and is not needed when using PdfFragment, PdfActivity or PdfActivity.

Parameters
context Application context.
licenseKey PSPDFKit license key.
applicationPolicy Application policy.
Throws
InvalidPSPDFKitLicenseException If license is not valid for this app.
PSPDFKitInitializationFailedException If current device isn't compatible with PSPDFKit (e.g. Android < 4.0 or wrong ABI) or if some other error occurred.
MissingDependencyException If RxAndroid or RxJava dependencies are missing in the containing app.

public static synchronized void initialize (Context context, String licenseKey)

Initializes PSPDFKit with a license key. This must be called before any other call to methods in this class.

This method can safely be called multiple times and is not needed when using PdfFragment, PdfActivity or PdfActivity.

Parameters
context Application context.
licenseKey PSPDFKit license key.
Throws
InvalidPSPDFKitLicenseException If license is not valid for this app.
PSPDFKitInitializationFailedException If current device isn't compatible with PSPDFKit (e.g. Android < 4.0 or wrong ABI) or if some other error occurred.
MissingDependencyException If RxAndroid or RxJava dependencies are missing in the containing app.

public static synchronized boolean isInitialized ()

Returns true if PSPDFKit is initialized and ready to use.

Returns
  • true if PSPDFKit was initialized.

public static boolean isLocalFileUri (Context context, Uri uri)

Checks whether or not PSPDFKit can extract a local filesystem path from the uri. If this method returns true PSPDFKit can directly access the document on the filesystem, and can thus achieve faster loading speeds. If the method returns false, use isOpenableUri(Context, Uri) to check whether PSPDFKit can still use the uri for document access.

Parameters
context Context for analyzing the uri.
uri Uri pointing to a PDF document.
Returns
  • true if PSPDFKit can access the file directly, or false if it needs to use a content resolver for access.

public static boolean isOpenableUri (Context context, Uri uri)

PSPDFKit can only open URIs from content providers that also provide size information. This determines if the document is openable directly from that URI. Note that this will not check if file actually exists.

Parameters
context Application context.
uri Android file URI.
Returns
  • true if the document can be directly opened.

public static synchronized void release (Context context)

Releases PSPDFKit library and all associated caches from memory.

BE WARNED: After this call all existing PdfDocument instances WILL be invalid and calling methods on them will result in a crash.

Parameters
context Application context.

public static boolean removeAnalyticsClient (AnalyticsClient client)

Remove a previously added AnalyticsClient from PSPDFKit. This method will return true if the client was successfully removed, or false if it was not removed. This usually happens if the client was not registered previously.

Parameters
client An AnalyticsClient to remove.
Returns
  • true if the client was successfully removed, otherwise false.

public static void setApplicationPolicy (ApplicationPolicy applicationPolicy)

Sets application policy for the loaded library. Make sure the library is initialized before calling this method.

Parameters
applicationPolicy New policy to be set.

public static void setLocalizationListener (LocalizationListener localizationListener)

Sets a new LocalizationListener to help with localizing SDK framework strings. WARNING: The localization listener is retained globally, so make sure it does not refer to any Activity context or it WILL leak memory.

Parameters
localizationListener new localization listener.

public static void setLoggingEnabled (boolean enabled)

Enables or disables PSPDFKit logcat logs. This is enabled by default.

Parameters
enabled true to enable logcat output, otherwise false.

public static void setNativeCrashDumpPath (String path)

Sets a directory into which native code minidumps will be stored for debugging of native crashes. T he minidumps are stored in Google Breakpad format.

Parameters
path Path for native crash dumps, must be writable.

public static void updateInternalUIContext (Context context)

Updates internal UI context and store it weakly to enable alert dialogs. In case getApplicationServices() is not an instance of ApplicationServiceImpl an error log will be emitted.

Parameters
context Context to store weakly.