public interface

DataProvider

com.pspdfkit.api.providers.DataProvider
Known Indirect Subclasses

Class Overview

Allows PSPDFKit to read data from any custom source (e.g. cloud providers, files, in-memory, data providers, etc.).

Classes implementing this interface need to implement all methods correctly to allow PSPDFKit to read the data.

Summary

Constants
int FILE_SIZE_UNKNOWN Constant value that can be return in getSize() to signal an error during retrieval of the actual file size.
Public Methods
abstract long getSize()
Return the actual file size of the data source which is provided by this data provider.
abstract String getTitle()
Displayable document title to be used if PDF document does not contain metadata.
abstract byte[] read(long size, long offset)
Called by PSPDFKit to read data from the document.
abstract void release()
Called when the provided document is being closed.

Constants

public static final int FILE_SIZE_UNKNOWN

Constant value that can be return in getSize() to signal an error during retrieval of the actual file size.

See Also
Constant Value: -1 (0xffffffff)

Public Methods

public abstract long getSize ()

Return the actual file size of the data source which is provided by this data provider. If the data provider can't determine the correct size (e.g. in case of an error) this method has to return FILE_SIZE_UNKNOWN.

Returns
  • Returns size of PDF document data in bytes, or FILE_SIZE_UNKNOWN in case of an error.

public abstract String getTitle ()

Displayable document title to be used if PDF document does not contain metadata. For example, for file-based providers this should return the filename. `.pdf` extensions will be stripped automatically.

Returns
  • Fallback document title if PDF document does not contain the required metadata. May be null.

public abstract byte[] read (long size, long offset)

Called by PSPDFKit to read data from the document. The returned byte array can be reused in subsequent calls to prevent excessive allocations.

Parameters
size Size of the data chunk to be read in bytes.
offset Offset from start of document of the data chunk to be read in bytes.
Returns
  • Byte array with document data of the exact same size or larger size than size parameter.

public abstract void release ()

Called when the provided document is being closed. Implementations are expected to release all resources (like closing of all streams and freeing of allocations).